1. 初始化
initWithString:
例子:
NSMutableAttributedString * mutableStr = [[NSMutableAttributedString alloc]initWithString:str];
2. 添加属性
2.1 添加单个属性
addAttribute: value: range:
例子:
[mutableStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(1, 2)];
2.2 添加多个属性
addAttributes:<#(nonnull NSDictionary<NSString *,id> *)#> range:<#(NSRange)#>
例子:
NSDictionary * arributes = @{NSFontAttributeName:[UIFont systemFontOfSize:18],
NSForegroundColorAttributeName:[UIColor whiteColor]};
[mutableStr addAttributes:arributes range:NSMakeRange(1, 2)];