关于NSMutableAttributedString属性字符串的用法
2016-06-28 18:32
441 查看
今天接触了属性字符串的部分用法,发现真是好用啊!,以下是部分用法:
效果图如下:
- 这样就可以把可变的字符串搞到label上了,另外还有加横穿线、下划线等多种用法。等着你去开发。
NSMutableAttributedString* attributedStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"合计: ¥%.2f",model.goodsCount * model.goodsModel.price]]; NSRange range1 = NSMakeRange(0, 3); NSRange range2 = NSMakeRange(3, attributedStr.length - 3); [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#6c6c6c"] range:range1];//设置前面三个字符的颜色 [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14.f] range:range1];//设置前面三个字符的字号大小 [attributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.f] range:range2];//设置后面字符的颜色 [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#fc4001"] range:range2];//设置后面字符的字号大小 UILable* label=[ [UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)]]; label.attributedText = attributedStr;
效果图如下:
- 这样就可以把可变的字符串搞到label上了,另外还有加横穿线、下划线等多种用法。等着你去开发。
相关文章推荐
- NSMutableArray(可变数组)
- iOS字符串个别字符特殊颜色
- UILabel的一些常用属性、NSAttributedString属性字符串
- NSAttributedString属性字符串
- 链式编程,iOS简单封装属性字符串,实现富文本.
- iOS中属性字符串转换成字符串
- Objective-C属性字符串NSAttributedString
- Swift3:NSMutableAttributeString的Range和NSRange问题
- hdu_5221_Occupation(树剖)
- Cubietruck---22.vold深入理解android第九章笔记
- 人生如逆旅,静读思己心
- git的使用
- svn切分支与分支合并
- hdu_5221_Occupation(树剖)
- Android root 原理
- Cubietruck---21.任意红外遥控器的使用方法
- Java中的super关键字
- 流氓软件也来争雄天下:
- 练习四1005畅通工程2
- Cubietruck---20.SurfaceFlinger创建过程分析