UILabel InfoLabel3;
Use a space as the truncation point. Locate the space, and then establish the Nsrang. Of course, you can also specify the scope yourself.
Nsrange range; Range = [Infolabel3.text rangeofstring:@ ""]; if (range.location! = nsnotfound) { NSLog (@ "found at location =%lu, length =%lu", (unsigned long) range.location, (Unsi gned long) range.length); Nsinteger startIndex = range.location; Nsinteger endIndex = infolabel3.text.length-1; Range = Nsmakerange (StartIndex, endIndex); Uifont *labelfont = [Uifont fontwithname:@ "Helveticaneue-bold" size:15]; nsmutableattributedstring *str = [[Nsmutableattributedstring alloc] initwithstring:@ "Using nsattributed String"]; [Str addattribute:nsforegroundcolorattributename value:[uicolor Lightgraycolor] range:range]; [Str addattribute:nsfontattributename value:labelfont range:range]; Infolabel3.attributedtext = str; } else{ NSLog (@ "not Found"); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS one Uilabel displays two fonts and colors