SoFunction
Updated on 2025-04-03

Set multiple font color codes for a paragraph of text in IOS

Given the range and the color that needs to be set, you can set multiple different font colors for a paragraph of text. The usage method is as follows:

Copy the codeThe code is as follows:

[self fuwenbenLabel:contentLabel FontNumber:[UIFont systemFontOfSize:15] AndRange:NSMakeRange(6, 1) AndColor:RGBACOLOR(34, 150, 253, 1)];

Copy the codeThe code is as follows:

//Set different font colors
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:];
//Set the font size
    [str addAttribute:NSFontAttributeName value:font range:range];
//Set text color
    [str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
    = str;
}

The above is the entire content of this article, I hope you like it.