时间:2021-06-18 08:46:38 | 栏目:iOS代码 | 点击:次
废话不多说了,大家先看下代码吧,具体待明日如下所示:
//str:要改变的字 //result:整个label里的字 //color: 字的颜色 - (NSMutableAttributedString *)changeSomeText:(NSString *)str inText:(NSString *)result withColor:(UIColor *)color { NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:result]; NSRange colorRange = NSMakeRange([[attributeStr string] rangeOfString:str].location,[[attributeStr string] rangeOfString:str].length); [attributeStr addAttribute:NSForegroundColorAttributeName value:color range:colorRange]; return attributeStr; }
效果: