Nsmutableattributedstring
Let testattributes = [Nsattributedstringkey. Foregroundcolor: Uicolor. Blue, Nsattributedstringkey. BackgroundColor: Uicolor. Yellow, Nsattributedstringkey. Strikethroughstyle:1] as [nsattributedstringkey : any]
Let testattributestring = nsattributedstring (string: "Rich Text Test", attributes:testattributes)
Self . TestLabel. attributedtext = testattributestring
Let prefix = "¥" + " + "
Let suffix = "¥" + "$"
Let string = prefix + suffix
let myattribute = [Nsattributedstringkey. Foregroundcolor: Uicolor. Lightgray,
Nsattributedstringkey. Strikethroughstyle: Nsunderlinestyle. Stylesingle. RawValue,
Nsattributedstringkey. Font: Uifont. Systemfont(ofsize: )] as [Nsattributedstringkey : Any ]
let redattribute = [Nsattributedstringkey. Foregroundcolor: Uicolor. Red,
Nsattributedstringkey. Font: Uifont. Systemfont(ofsize: )] as [Nsattributedstringkey : Any ]
Let attstring = nsmutableattributedstring (string:string)
Attstring. AddAttributes (Redattribute, Range:nsrange. Init (location: 0, Length:prefix. count))
Attstring. AddAttributes (myattribute, Range: nsrange. Init (location:prefix. Count, Length:suffix. count))
Self . Titlelabel. attributedtext = attstring
Use of Swift nsattributedstring