您可以使用NSAttributedString
这样调整字母间距。
在Objective-C中:
You can adjust letter spacing like this, using NSAttributedString
.
In Objective-C:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"The Clash"];
[attributedString addAttribute:NSKernAttributeName
value:@(1.4)
range:NSMakeRange(0, 9)];
self.label.attributedText = attributedString;
在Swift 3中:
let attributedString = NSMutableAttributedString(string: "The Clash")
attributedString.addAttribute(NSKernAttributeName, value: CGFloat(1.4), range: NSRange(location: 0, length: 9))
label.attributedText = attributedString
在 Swift 4 及以后版本:
label.attributedText = NSAttributedString(string: "The Clash", attributes: [.kern: 1.4])
有关字距调整的更多信息,请参阅《文本编程指南中的排版概念》。
我认为 TextKit 没有自动匹配粗体和普通文本之间字间距的功能。
NSAttributedString.Key.kern
。 - Jason Silver