具有删除线的多行属性字符串

kot*_*ska 1 nsattributedstring uilabel ios swift swift3

我有一个标签:

label.numberOfLines = 0
Run Code Online (Sandbox Code Playgroud)

而我正在努力使这个标签的文字删除:

let index: NSMutableAttributedString = NSMutableAttributedString(string: label.text!)
index.addAttributes([NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue, NSStrikethroughColorAttributeName: UIColor.red], range: NSMakeRange(0, index.length))
label.textColor = UIColor.red
label.attributedText = index
Run Code Online (Sandbox Code Playgroud)

属性字符串是否适用于多行或使用numberOfLines设置为0的标签?如果是这样,如何使多行文字删除?

Ale*_*nov 7

如果在之前添加NSBaselineOffsetAttributeName,则可以使用多行正常工作:

let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: (object?.title)!)
attributeString.addAttribute(NSBaselineOffsetAttributeName, value: 0, range: NSMakeRange(0, attributeString.length))
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length))
Run Code Online (Sandbox Code Playgroud)