NSString *str = @ "0123456789";//label content nsmutableattributedstring *str1 = [[Nsmutableattributedstring alloc] initwithstring:str];//setting font color based on subscript index [str addattribute:nsforegroundcolorattributename value:[uicolor BlueColor] Range : Nsmakerange (0,5)]; [Str addattribute:nsforegroundcolorattributename value:[uicolor Redcolor] Range:nsmakerange (6,12)]; [Str addattribute:nsforegroundcolorattributename value:[uicolor Greencolor] Range:nsmakerange (19,6)];// Set font style size according to subscript index (style only valid for letters) [str addattribute:nsfontattributename value:[uifont fontwithname:@ "ARIAL-BOLDITALICMT" size:30.0] Range:nsmakerange (0, 5)]; [Str addattribute:nsfontattributename value:[uifont fontwithname:@ "Helveticaneue-bold" size:30.0] Range:NSMakeRange (6, 12)]; [Str addattribute:nsfontattributename value:[uifont fontwithname:@ "Courier-boldoblique" size:30.0] Range: Nsmakerange (6)];_mylabel.attributedtext = str1;//above method is iOS6, before iOS6 need to use to a third party library Tttattributedlabel, There are also import coretext.frame frames
Ios:uilabel setting different font colors