7

ho aggiunto alcuni attributi ai miei pulsanti attributedTitleCome rimuovere gli attributi da NSAttributeString swift?

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) 

Come posso rimuovere NSStrikethroughStyleAttributeName da esso dopo fare clic sul pulsante?

+0

Wow. Questa è la domanda, cosa mi interessava. Grazie per la domanda. È un miracolo. Per favore condividilo – PiraTa

+0

Prego PiraTa ... Grazie! :) –

risposta

6

utilizzare il metodo removeAttribute:

attr.removeAttribute(NSStrikethroughStyleAttributeName, range: NSMakeRange(0, attr.length)) 
4

È molto semplice. È possibile utilizzare questo metodo da NSMutableAttributedString classe

func removeAttribute(_ name: String, 
       range range: NSRange) 

Nel tuo caso

attr.removeAttribute(NSStrikethroughStyleAttributeName , range:NSMakeRange(0, attr.length))