NSMutableAttributedString可变属性字符串的用法
适用于:当你想对一个字符串中的某几个字符更改颜色,字体。。。
NSString *string = @"今日营养配餐提供热量1800千卡,需要饮食之外额外补充钙10mg,铁20mg,锌9.5mg,叶酸200μgDFE,维生素D 10ug,维生素B1 1.2mg,维生素B2 1.2mg。";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];
NSRange range = [string rangeOfString:@"今日营养配餐"];
[attributedString addAttribute:NSForegroundColorAttributeName value:JYEColor(72, 75, 91) range:range];
[attributedString addAttribute:NSFontAttributeName value:[self jyeFontWithName:@"PingFangSC-Medium" size:13] range:range];
hotLabel.attributedText = attributedString;
使用场景:处理 属性字符串 文字居中
NSMutableParagraphStyle *paragrapStyle = [[NSMutableParagraphStyle alloc]init];
paragrapStyle.alignment = NSTextAlignmentCenter;//文字居中属性
NSString * shareCountStr = [NSString stringWithFormat:@"———已有%@人分享———",self.dishAdviceShareCountString];
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:shareCountStr];
NSRange range = [shareCountStr rangeOfString:self.dishAdviceShareCountString];//人数 做颜色处理
[attributedString addAttribute:NSForegroundColorAttributeName value:JYEColor(255, 48, 99) range:range];
[attributedString addAttribute:NSFontAttributeName value:[JYEToolModel jyeFontWithName:@"PingFangSC-Regular" size:12] range:range];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:range];
shareNumLabel.attributedText = attributedString;
NSMutableAttributedString可变属性字符串的用法的更多相关文章
- (转)iOS 属性字符串
富文本的基本数据类型是NSAttributedString.**属性化字符串**(attributed string)是把属性设置到某些字符上的字符串.属性可以是任何键值对,但是为了实现富文本,则通常 ...
- Delphi中stringlist分割字符串的用法
Delphi中stringlist分割字符串的用法 TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 1.CommaT ...
- Python中用format函数格式化字符串的用法
这篇文章主要介绍了Python中用format函数格式化字符串的用法,格式化字符串是Python学习当中的基础知识,本文主要针对Python2.7.x版本,需要的朋友可以参考下 自python2. ...
- 属性字符串的replaceCharactersInRange方法
一,实验: 1> 让 range 的 length 参数为0,以下代码输出属性字符串的结果为12354 NSMutableAttributedString *attrStr = [[NSMuta ...
- SQL反模式学习笔记6 支持可变属性【实体-属性-值】
目标:支持可变属性 反模式:使用泛型属性表.这种设计成为实体-属性-值(EAV),也可叫做开放架构.名-值对. 优点:通过增加一张额外的表,可以有以下好处 (1)表中的列很少: (2)新增属性时,不需 ...
- 属性字符串(NSAttributedString)的简单应用
属性字符串NSAttributedString 可以对字符串附加格式信息,由于对于对不同文本片段使用不同的格式,属性字符串类特别合适. IOS 6中对样式文本有了大改善,大部分主要的UIKit控件都允 ...
- iOS UILable和属性字符串的使用
UILable的常用方法和属性 设置文字颜色(默认为黑色) @property(nonatomic,strong) UIColor *textColor 设置显示文字 @property(no ...
- 给iOS开发新手送点福利,简述文本属性Attributes的用法
给iOS开发新手送点福利,简述文本属性Attributes的用法 文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSF ...
- CSS3动画属性animation的用法
转载: 赞生博客 高端订制web开发工作组 » CSS3动画属性animation的用法 CSS3提供了一个令人心动的动画属性:animation,尽管利用animation做出来的动画没有flash ...
随机推荐
- ural 1339. Babies
1339. Babies Time limit: 1.0 secondMemory limit: 64 MB O tempora! O mores! Present-day babies progre ...
- BZOJ3068 : 小白树
枚举每条树边,将其断开,那么两侧肯定取带权重心最优. 考虑如何求出每个子树的重心,枚举其所有儿子,通过重量关系就可以判断出重心位于哪棵子树. 然后将那棵子树的重心暴力往上爬即可,因为每个点作为重心肯定 ...
- 关于storm的Spout、Bolt、及其可靠性
本文导读: Component全家谱结构图 Spout分析 ——类图 ——分析(接口实现).结论 ——可靠的与不可靠的消息(推荐) Bolt分析 ——类图 ——分析(接口实现).结论 ——可靠的与不 ...
- Mysql如何修改unique key
link:http://www.netingcn.com/mysql-modifyunique-key.html mysql可以使用unique key来确保数据的准确性,unique key可以是一 ...
- Android 读取蓝牙设备信息开发
(1)Android手机一般以客户端的角色主动连接SPP协议设备(接上蓝牙模块的数字传感器),连接流程是: 1.使用registerReceiver注册BroadcastReceiver来获取蓝牙状态 ...
- Android自动化测试框架
1.Monkeyrunner:优点:操作最为简单,可以录制测试脚本,可视化操作:缺点:主要生成坐标的自动化操作,移植性不强,功能最为局限: 2.Rubotium:主要针对某一个APK进行自动化测 ...
- ACM n-1位数
n-1位数 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2)位的整数,则求出w的后n-1位的 ...
- 解决clang: error: no such file or directory: such file or directory:的问题
一,详细问题描述 clang: error: no such file or directory: 'xxx/src/GGBaCollectionViewCell.m' clang: error: n ...
- sql分页代码
//三种sql分页语句 SELECT TOP 分页尺寸 * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY id) AS RowNumber,* FROM Blob ...
- 李洪强iOS经典面试题129
1. 怎么解决缓存池满的问题(cell) ios中不存在缓存池满的情况,因为通常我们ios中开发,对象都是在需要的时候才会创建,有种常用的说话叫做懒加载,还有在UITableView中一般只会创建刚开 ...