您可以像这样调整字母间距,使用NSAttributedString
.
在 Objective-C 中:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"The Clash"];
[attributedString addAttribute:NSKernAttributeName
value:@(1.4)
range:NSMakeRange(0, 9)];
self.label.attributedText = attributedString;
在斯威夫特 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])
有关字距调整的更多信息,请参阅 Text Programming Guide 中的 Typographical Concepts。
我不认为有一个 TextKit 功能可以自动匹配粗体和常规文本之间的字体间距。