Set multiple font color codes for a text segment in IOS
This article mainly introduces how to set multiple font color codes for a text section in IOS, which is very practical. For more information, see.
Given the range and the color to be set, you can set different font colors for a text segment. The usage is as follows:
The Code is as follows:
[Self fuwenbenLabel: contentLabel FontNumber: [UIFont systemFontOfSize: 15] AndRange: NSMakeRange (6, 1) AndColor: RGBACOLOR (34,150,253, 1)];
The Code is as follows:
// Set different font colors
-(Void) fuwenbenLabel :( UILabel *) labell FontNumber :( id) font AndRange :( nsange) range AndColor :( UIColor *) vaColor
{
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString: labell. text];
// Set the font size
[Str addattriename: NSFontAttributeName value: font range: range];
// Set the text color
[Str addattriename: NSForegroundColorAttributeName value: vaColor range: range];
Labell. attributedText = str;
}
The above is all the content of this article. I hope you will like it.