本文介绍了在Interface Builder中的UILabel上更改字符间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Interface Builder在UILabel文本上更改字符间距(轨迹)?如果没有,是否有办法在已经使用属性文本创建的现有UILabel上以编程方式进行此操作?
Is there anyway to change the character spacing (track) on UILabel text using Interface Builder? If not, is there a way to do it programmatically on an existing UILabel that was already created with attributed text?
推荐答案
现在最终使用它来获取现有的属性文本并进行修改以增加字符间距:
Ended up using this for now to get existing attributed text and modify to add character spacing:
let attributedString = discoveryTitle.attributedText as NSMutableAttributedString
attributedString.addAttribute(NSKernAttributeName, value: 1.0, range: NSMakeRange(0, attributedString.length))
discoveryTitle.attributedText = attributedString
迅速3:
let attributedString = NSMutableAttributedString(string: discoveryTitle.text)
attributedString.addAttribute(NSKernAttributeName, value: CGFloat(1.0), range: NSRange(location: 0, length: attributedString.length))
discoveryTitle.attributedText = attributedString
使用NSRange代替NSMakeRange在Swift 3中有效.
Using NSRange instead of NSMakeRange works in Swift 3.
这篇关于在Interface Builder中的UILabel上更改字符间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!