NSMutableAttributedString 的使用

NSMutableAttributedString 可以使用多种中方法创建的,在没有封装好直接就记录下自己平时使用的习惯吧。

 NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString: @"富文本使用"];
// 设置约束字典
NSDictionary *attriDict = @{NSForegroundColorAttributeName:[UIColor redColor]};
// 设置字典的使用范围
[attriStr addAttributes: attriDict range:NSMakeRange(3, 2)];

简单的就这3句就行了,注意Range不要越界。
以下是一些字典常用的Key值,

// 字体大小 value 用 UIFont
NSFontAttributeName  

// 字体颜色 value 用 UIColor
NSForegroundColorAttributeName

// 字体背景颜色 value 用 UIColor
NSBackgroundColorAttributeName 

贴个效果图

NSMutableAttributedString 的使用_第1张图片
简单使用.png

你可能感兴趣的:(NSMutableAttributedString 的使用)