NSMutableAttributedString *styleText = [[NSMutableAttributedString alloc] initWithString:plaintext];
NSDictionary *attributes = @{
NSFontAttributeName : [UIFont boldSystemFontOfSize:_statusLabel.font.pointSize]
};
NSRange nameRange = [plaintext rangeOfString:title];
[styleText setAttributes:attributes range:nameRange];
_statusLabel.attributedText = styleText;
添加属性:
[styleText addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:16.0]
range:NSMakeRange(2, 2)];
NSMutableAttributedString:带属性的字符串
常见的属性及说明
NSFontAttributeName 字体
NSParagraphStyleAttributeName 段落格式
NSForegroundColorAttributeName 字体颜色
NSBackgroundColorAttributeName 背景颜色
NSStrikethroughStyleAttributeName删除线格式
NSUnderlineStyleAttributeName 下划线格式
NSStrokeColorAttributeName 删除线颜色
NSStrokeWidthAttributeName删除线宽度
NSShadowAttributeName 阴影