我在我的按钮上添加了一些属性attributedTitle
let attr = NSMutableAttributedString(string: currTitle)
attr.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attr.length))
attr.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: NSMakeRange(0, attr.length))
currButton?.setAttributedTitle(attr, forState: UIControlState.Normal)
单击按钮后如何从中删除NSStrikethroughStyleAttributeName?
使用removeAttribute
方法:
attr.removeAttribute(NSStrikethroughStyleAttributeName, range: NSMakeRange(0, attr.length))
非常简单。您可以从NSMutableAttributedString类
使用此方法func removeAttribute(_ name: String,
range range: NSRange)
根据您的情况
attr.removeAttribute(NSStrikethroughStyleAttributeName , range:NSMakeRange(0, attr.length))
在Swift 5中
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: "YourStringHere")
attributeString.removeAttribute(NSAttributedString.Key.strikethroughStyle, range: NSMakeRange(0, attributeString.length))
yourLblHere.attributedText = attributeString