NSAttributedString字符串属性

来源:互联网 发布:药品网络市场监管 编辑:程序博客网 时间:2024/05/31 06:24

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)];




0 0