How to remove attributes from the NSAttributedString swift? How to remove attributes from the NSAttributedString swift? swift swift

How to remove attributes from the NSAttributedString swift?


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))


In Swift 5

let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: "YourStringHere")attributeString.removeAttribute(NSAttributedString.Key.strikethroughStyle, range: NSMakeRange(0, attributeString.length))yourLblHere.attributedText = attributeString