首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当我更改kerning时,UITextView样式被重置

当我更改kerning时,UITextView样式被重置
EN

Stack Overflow用户
提问于 2020-02-12 11:36:03
回答 1查看 80关注 0票数 0

当我更改kerning时,样式将被重置。例如,当我更改文本大小或颜色时,它会被保存,但是当我更改kerning时,样式UITextView会被重置。

代码语言:javascript
复制
@IBAction func sizeTextEdit(_ sender: Any) {

        self.textOne?.font = UIFont.systemFont(ofSize: CGFloat(sizeText.value * 1))
    }

@IBAction func kernTextEdit(_ sender: Any) {

    let textString = textOne.text
    let attrs: [NSAttributedString.Key : Any] = [.kern: kernText.value]
        textOne?.attributedText = NSAttributedString(string: textString!, attributes: attrs)
    }

如您在第一个屏幕截图中看到的,我增加了字体,然后增加了字母与字体大小之间的距离,并重置了

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-12 15:25:07

font属性仅更改text属性的字体。attributedText是一个不同的属性,因此您也需要为它定义font

代码语言:javascript
复制
let attrs: [NSAttributedString.Key : Any] = [.kern: kernText.value,
                                             .font: UIFont.systemFont(ofSize: CGFloat(sizeText.value * 1))]
textOne?.attributedText = NSAttributedString(string: textString!, attributes: attrs)

另外,如果您想要这样做,最好坚持一个属性,在本例中是attributedText,否则您必须保持它们的同步。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60187468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档