[ios]字符串不同位置显示不同颜色
2016-05-13 14:10
381 查看
NSString* str=@“颜色分段显示”;
NSMutableAttributedString *coloredStr = [[NSMutableAttributedString
alloc]
initWithString:str];
[coloredStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor] range:NSMakeRange(0,2)];
[coloredStr addAttribute:NSForegroundColorAttributeName value:[UIColor
blackColor] range:NSMakeRange(2,4)];
效果为 “颜色”显示红色 “分段显示”显示黑色。
NSMutableAttributedString *coloredStr = [[NSMutableAttributedString
alloc]
initWithString:str];
[coloredStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor] range:NSMakeRange(0,2)];
[coloredStr addAttribute:NSForegroundColorAttributeName value:[UIColor
blackColor] range:NSMakeRange(2,4)];
效果为 “颜色”显示红色 “分段显示”显示黑色。
相关文章推荐
- ios中关于各种空-nil、Nil、NSNULL、NULL
- Ios 实现 滑动cell 伸缩的核心代码
- iOS中如何在欢迎界面中动态加载广告
- iOS开发-Runloop详解(简书)
- iOS开发-Runtime详解(简书)
- iOS三句话实现文本转语音:AVSpeechSynthesizer
- abort()函数
- CodingNet - Learning - 2
- 获取当前日期和星期 iOS
- Google发布Gboard,一个iOS输入法,让你不用浏览器也能搜索
- ios之音频系列
- iOS tableView动态创建分组及组内排序
- IOS 使用AES/ECB/PKCS7Padding 加密、解密数据
- iOS关于小数点的四舍五入
- iOS开发企业版ipa分发
- (最新)iOS后台运行时间
- iOS Xcode 自带crash 崩溃问题的追踪方法
- iOS在xib或storyboard里为控件添加圆角、外框和外框颜色
- iOS自定义转场详解02——实现Keynote中的神奇移动效果
- iOS 支付宝支付开发集成流程,这里记载的是签名保存在前台的集成,