[UITextView样式在我更改字距时会重置

问题描述 投票:0回答:1

我更改字距调整后,样式会重置。例如,当我更改文本大小或颜色时,将保存它,但是当我更改字距调整时,将重置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)
    }

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

enter image description here

我更改字距调整后,样式会重置。例如,当我更改文本大小或颜色时,将保存它,但是当我更改字距调整时,将重置UITextView样式@IBAction func sizeTextEdit(_ sender:...

swift uitextview kerning nsmutableparagraphstyle
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.