当我更改kerning时,样式将被重置。例如,当我更改文本大小或颜色时,它会被保存,但是当我更改kerning时,样式UITextView会被重置。
@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)
}如您在第一个屏幕截图中看到的,我增加了字体,然后增加了字母与字体大小之间的距离,并重置了。

发布于 2020-02-12 15:25:07
font属性仅更改text属性的字体。attributedText是一个不同的属性,因此您也需要为它定义font:
let attrs: [NSAttributedString.Key : Any] = [.kern: kernText.value,
.font: UIFont.systemFont(ofSize: CGFloat(sizeText.value * 1))]
textOne?.attributedText = NSAttributedString(string: textString!, attributes: attrs)另外,如果您想要这样做,最好坚持一个属性,在本例中是attributedText,否则您必须保持它们的同步。
https://stackoverflow.com/questions/60187468
复制相似问题