#pragma mark 同一个label中间几个字 变颜色、大小都能改变
//用法:self.integralLabel.attributedText =[NSString getLabelChangeColor:[UIColor orangeColor] andFont:[UIFont systemFontOfSize:22] andString1:@"我的" andChangeString:@"大的" andGetstring3:@"自己"];
+(NSMutableAttributedString*)getLabelChangeColor:(UIColor*)color andFont:(UIFont*)fout andString1:(NSString*)string1 andChangeString:(NSString*)string2 andGetstring3:(NSString*)string3{
//string2 是变色的部分
NSString *inteStr = [NSString stringWithFormat:@"%@%@%@",string1,string2,string3];
NSMutableAttributedString *inteMutStr = [[NSMutableAttributedString alloc] initWithString:inteStr];
//设置中间变红的字体大小颜色
NSRange orangeRange = NSMakeRange([[inteMutStr string] rangeOfString:string2].location, [[inteMutStr string] rangeOfString:string2].length);
[inteMutStr addAttributes:@{NSFontAttributeName:fout,NSForegroundColorAttributeName:color} range:orangeRange];
return inteMutStr;
}
网友评论