Given range and the color you want to set, you can set several different font colors for a paragraph of text, using the following methods:
Copy Code code as follows:
[Self Fuwenbenlabel:contentlabel fontnumber:[uifont systemfontofsize:15] Andrange:nsmakerange (6, 1) AndColor: Rgbacolor (34, 150, 253, 1)];
Copy Code code as follows:
Set different font colors
-(void) Fuwenbenlabel: (Uilabel *) Labell Fontnumber: (id) font andrange: (nsrange) Range Andcolor: (Uicolor *) Vacolor
{
nsmutableattributedstring *str = [[Nsmutableattributedstring alloc] initWithString:labell.text];
Set Font size
[Str addattribute:nsfontattributename value:font Range:range];
Set Text color
[Str addattribute:nsforegroundcolorattributename value:vacolor Range:range];
Labell.attributedtext = str;
}
The above mentioned is the entire content of this article, I hope you can enjoy.