如何从NSAttributedString swift中删除属性?

Sal*_*mua 12 setattribute nsattributedstring ios nsmutableattributedstring swift

我在按钮attributesTitle中添加了一些属性

 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)
Run Code Online (Sandbox Code Playgroud)

按钮点击后如何从中删除NSStrikethroughStyleAttributeName?

aya*_*aio 10

使用removeAttribute方法:

attr.removeAttribute(NSStrikethroughStyleAttributeName, range: NSMakeRange(0, attr.length))
Run Code Online (Sandbox Code Playgroud)