美文网首页
NSMutableAttributedString 的使用

NSMutableAttributedString 的使用

作者: 广东煲仔饭049 | 来源:发表于2016-07-18 11:37 被阅读46次

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 

贴个效果图

简单使用.png

相关文章

网友评论

      本文标题:NSMutableAttributedString 的使用

      本文链接:https://www.haomeiwen.com/subject/vvmpjttx.html