swift UILable 文字颜色分段
来源:互联网 发布:ar卡片制作软件 编辑:程序博客网 时间:2024/05/16 00:50
iOS开发中经常会遇到这样的问题就是一个Label 中的文字需要两种以上的颜色现实
比如注册按钮下一般会有服务协议,这里的文字一般都会做区分
如下图
我们直接看代码
- UILabel *hintLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 120, 320, 66)];
- hintLabel.numberOfLines=0;
- [self.view addSubview:hintLabel];
- NSMutableAttributedString *hintString=[[NSMutableAttributedString alloc]initWithString:@"点击注册按钮即表示您已同意西游隐私条款和服务协议"];
- //获取要调整颜色的文字位置,调整颜色
- NSRange range1=[[hintString string]rangeOfString:@"西游隐私条款"];
- [hintString addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:range1];
- NSRange range2=[[hintString string]rangeOfString:@"服务协议"];
- [hintString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range2];
- hintLabel.attributedText=hintString;
其实,就是使用到了NSMutableAttributedString 的功能,Label设置 attributedText就好了
0 0
- swift UILable 文字颜色分段
- iOS Label文字分段颜色
- iOS Label文字分段颜色
- IOS UILable 设置部分文字的颜色颜色
- Swift UILable
- android textview 分段设置文字颜色
- UILabel 分段改变文字颜色和字体
- swift UILable换行问题
- Swift 标签控件(UILable)
- UILable自适应文字高度
- swift 设置statusBar的文字颜色
- UILable颜色设置
- UILable 字体颜色修改
- swift中UILable的使用
- UILable文字滚动 跑马灯
- UILable文字置顶的解决方案
- UILable 设置多种字体颜色
- Swift开发教程--如何设置状态栏的文字颜色
- 一个页面内,多个listview的实现
- android------通用ViewHolder 通用Adapter
- LeetCode---Pascal's Triangle
- 论文阅读《Spatial Transformer Networks》
- Leetcode || Substring with Concatenation of All Words
- swift UILable 文字颜色分段
- swift UIButton
- 第3条:用私有构造器或者枚举类型强化Singleton属性
- xpath相对当前节点定位方法总结
- 对于MSP430与SIM900A无法通信的问题解决
- 编程之美-求二进制数中1的个数方法整理
- zoj 1601 Count the Colorst(线段树)
- swift UIButton 设置动态图片
- 在request中获取项目路径