【发布时间】:2018-02-16 16:42:00
【问题描述】:
我需要为UILabel 呈现的文本设置两个属性:字母之间的间距(kern)及其删除线样式。基于NSAttributedStringKey 文档,我为UILabel 创建了以下扩展:
extension UILabel {
func setStrikeThroughSpacedText(text: String, kern: CGFloat?) {
var attributes: [NSAttributedStringKey : Any] = [:]
if let kern = kern {
attributes[.kern] = kern
}
attributes[.strikethroughStyle]
= NSNumber(integerLiteral: NSUnderlineStyle.styleSingle.rawValue)
self.attributedText = NSAttributedString(string: text,
attributes: attributes)
}
}
但是,.kern 键似乎以某种方式与 .strikethroughStyle 键发生冲突,因为如果我指定 kern,则会应用 kern,但不会应用删除线样式。如果我不指定 kern(因此扩展不应用 .kern 属性),删除线样式有效。
任何人都有不同的方法来解决这个错误(我认为这是一个错误)?
【问题讨论】:
-
这确实看起来像一个错误。你提交雷达了吗?
-
还没有……虽然我刚刚在 iOS 11 上的模拟器中对其进行了测试,但它似乎在那里工作……所以他们似乎在那里修复了它……
-
查看更新后的结果。
标签: ios swift ios10 swift4 nsattributedstring