我正在使用自定义表格 View 单元格并动态调整它们的大小以适合它们的内容(使用 UICell 上的约束),但我无法控制字母和线条之间的间距,我正在使用此代码
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 40
var attrString = NSMutableAttributedString(string: str!)
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))
最佳答案
对于 objective-c 中字母之间的间距:
NSAttributedString * attributedString =
[[NSAttributedString alloc]
initWithString:text
attributes: @{ NSKernAttributeName : @(1.20f) }];
label.attributedText = attributedString;
1.20f 是您希望字母之间的间距。标签是一个 UILabel
。
swift :
http://rajiev.com/ios-font-kerning-with-swift-and-nsattributedstring/
关于iphone - 如何使用 swift 更改 UICell 上字母和线条之间的间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874018/