UI让项目中的字符串NSString 转换为富文 NSMutableAttributedString
...
- (NSMutableAttributedString *)StringToNSMutableAttributedString: (NSString *)str font:(float)font color:(UIColor *)strColor {
NSRange strRange = NSMakeRange(0, str.length);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
UIFont *fontStr = [UIFont fontWithName:@"PingFangSC-Bold" size:font];
if (fontStr == nil) {
fontStr = [UIFont systemFontOfSize:font];
}
// 字体大小
[attributedString addAttribute:NSFontAttributeName value:fontStr range:strRange];
// 字体颜色
[attributedString addAttribute:NSForegroundColorAttributeName value:strColor range:strRange];
return attributedString;
}
...
网友评论