NSMutableAttributedString初探
来源:互联网 发布:淘宝男士鞋 编辑:程序博客网 时间:2024/04/25 21:27
NSMutableAttributedString 指具有多属性字符串。
效果如图1
只需要增加一行代码
效果如图2
设置前如图3所示,设置后如图4所示
*需要注意的是,给UILabel设置内容时,需使用setAttributedText函数。
如:字符串中有不同颜色的字。
NSString *string = @"我的名字叫kendami啊";NSMutableAttributedString *aString = [[NSMutableAttributedString alloc]initWithString:string];[aString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:[string rangeOfString:@"kendami"]];[self.label setAttributedText:aString];其中关键字是:NSForegroundColorAttributeName
效果如图1
图1
字符串中有不同字体只需要增加一行代码
[aString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:[string rangeOfString:@"kendami"]];关键字:NSFontAttributeName:字体
效果如图2
图2
设置行间距NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];[paragraphStyle setLineSpacing:10.0f];//每行间距10[aString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [string length])];self.label.numberOfLines = 0;关键字:NSParagraphStyleAttributeName
设置前如图3所示,设置后如图4所示
图3
图4
NSMutableAttributedString还包括很多其他属性,具体可查看UIKIT下NSAttributedString.h头文件。*需要注意的是,给UILabel设置内容时,需使用setAttributedText函数。
0 0
- NSMutableAttributedString初探
- 初探NSAttributedString和NSMutableAttributedString的使用
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString
- NSMutableAttributedString 使用
- NSMutableAttributedString使用
- NSMutableAttributedString 文字处理 。。。
- NSMutableAttributedString使用
- 从背景差分到深度学习方法的目标检测与前背景分离
- 【LeetCode】20. Valid Parentheses
- Java序列化与JSON序列化大比拼
- js拖拽文件上传
- 第三周项目三输出星号图
- NSMutableAttributedString初探
- 删除提示找不到该项目的文件_20160317
- 第三周训练 打印星号图
- struts 文件上传处理
- java中Static的作用
- 容联云通讯IM
- 持久化对象的要求
- Stars--树状数组
- [Songqw.Net 基础]WPF插件化中同步Style