I have added some attributes to my buttons 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)
How can I remove NSStrikethroughStyleAttributeName from it after button click?
Use the removeAttribute
method:
attr.removeAttribute(NSStrikethroughStyleAttributeName, range: NSMakeRange(0, attr.length))
It is very simple. You can use this method from NSMutableAttributedString class
func removeAttribute(_ name: String,
range range: NSRange)
In your case
attr.removeAttribute(NSStrikethroughStyleAttributeName , range:NSMakeRange(0, attr.length))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With