富文本,NSAttributedString 与 coreText
来源:互联网 发布:gps漂移过滤算法 源码 编辑:程序博客网 时间:2024/05/16 11:16
在ios 6 以前,绘制富文本,需要重写view的drawRect 方法,使用 coreText 绘制 。ios6以后,系统为UILabel 添加了对富文本的支持。同时,对一些coreText 层需要的属性,在NS 层进行了封装,现在使用起来非常的简便,比如
<pre name="code" class="html"> NSString * countStr = @"20"; NSString * memberCountString = [NSString stringWithFormat:@"当前%@人活跃",countStr]; NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:memberCountString]; NSRange range = [memberCountString rangeOfString:countStr]; NSDictionary * attriDic = @{NSForegroundColorAttributeName:[UIColor redColor]}; [attributedString addAttributes:attriDic range:range]; self.memberCountLabel.attributedText = attributedString;
这样设置之后,显示出来的文字中,数字 “20” 将以红色显示,典型的富文本应用。而这里使用的,字体颜色的key 使用了NS层封装的 NSForegroundColorAttributeName,颜色也使用了UIColor,如果按以前的 kCTForegroundColorAttributeName,CGColor 的方式去设置,就不行了.
0 0
- 富文本,NSAttributedString 与 coreText
- 富文本NSAttributedString与NSMutableAttributedString
- 富文本之NSAttributedString与NSMutableAttributedString
- iOS_富文本(NSAttributedString)
- NSAttributedString 富文本详解
- NSAttributedString(富文本)用法
- iOS富文本(NSAttributedString)
- NSMutableAttributedString/NSAttributedString 富文本设置
- iOS开发-NSAttributedString富文本
- 常用富文本NSAttributedString浅析
- iOS之富文本NSAttributedString
- coreText自定义富文本Label
- coreText自定义富文本Label
- coreText自定义富文本Label
- coreText自定义富文本Label
- iOS-[NSAttributedString]设置富文本和计算富文本高度
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- iOS NSMutableAttributedString/NSAttributedString 富文本设置
- C# json 一维数组 和 二维数组的转换
- POJ 3258 River Hopscotch(二分求最小中的最大)
- 风靡职场的十大面试题!
- GPU编程配置
- php 获取今日 昨日 本周 上一周 本月 近三个月的起至时间戳
- 富文本,NSAttributedString 与 coreText
- Install MongoDB on OS X
- [LeetCode 224]Basic Calculator
- RESTEasy hello world example
- php使用curl模拟提交XML
- Retrofit原理及调用流程分析
- s3c2440 LCD(sony x35)
- 搭建自己的github ---Gitorious
- 文章标题