一个字符串设置不同颜色,设置字符串某一部分的颜色
2016-04-16 10:40
330 查看
NSString *str =
@"我是:大帅哥";
NSMutableAttributedString *attrStr = [[NSMutableAttributedString
alloc]initWithString:str];
[attrStr addAttribute:NSForegroundColorAttributeName
value:[UIColor
redColor] range:NSMakeRange(0,3)];//从第0个字符开始数设置3个字符
_myLbl.attributedText = attrStr;
显示效果
@"我是:大帅哥";
NSMutableAttributedString *attrStr = [[NSMutableAttributedString
alloc]initWithString:str];
[attrStr addAttribute:NSForegroundColorAttributeName
value:[UIColor
redColor] range:NSMakeRange(0,3)];//从第0个字符开始数设置3个字符
_myLbl.attributedText = attrStr;
显示效果
相关文章推荐
- BAT批处理实现字符串截取功能
- C#中英文混合字符串截取函数
- ASP 支持中文的len(),left(),right()的函数代码
- JavaScript substr() 字符串截取函数使用详解
- js substring()字符串截取函数
- 可以保证单词完整性的PHP英文字符串截取代码分享
- Shell脚本8种字符串截取方法总结
- Mysql字符串截取函数SUBSTRING的用法说明
- 求助:关于字符串截取的问题
- PHP 截取字符串
- python 字符串截取
- 【phpcms-v9】改造phpcms-v9自带的字符串截取函数
- 懒得优化了,字符串截取和重复字符串计数
- Linux shell脚本的字符串截取
- C# 关于字符串按需求截取,替代写法
- 字符串的算法
- scanf的使用,对于以前的认知我真是弱爆了
- PHP之Smarty模板的基本使用
- java 字符串模糊匹配
- File文件创建路径,修改文本内容,截取文本内容