UILabel设置多种字体、颜色
来源:互联网 发布:双色球预测软件下载 编辑:程序博客网 时间:2024/06/11 12:36
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String,try your best to test attributed string text"];[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(0, 5)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(6, 12)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(19, 6)];UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 320 - 40, 90)];attrLabel.attributedText = str;attrLabel.numberOfLines = 0;
说明
NSMutableAttributedString类可以添加各种样式,常用的设置key有:
- NSForegroundColorAttributeName 设置前景色,也就是文本颜色
- NSFontAttributeName 设置字体
- NSBackgroundColorAttributeName 设置背景色
更多内容点击NSMutableAttributedString进去查看声明。
原文来自:标哥的技术博客
0 0
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色
- UILabel设置多种字体、颜色 (NSMutableAttributedString)
- UILabel设置多种字体、颜色(文本中字体不同颜色)
- UILabel 显示多种字体和颜色
- UILable 设置多种字体颜色
- POI 设置字体多种颜色
- iOS 设置字体颜色和多种字体
- UILabel设置不同的字体颜色
- 给UIlabel设置不同字体 颜色 下划线
- iOS:UILabel设置不同字体颜色
- UILabel设置不同的字体颜色
- UILabel 设置渐变颜色字体
- UILabel设置不同的字体不同的颜色
- iOS 设置UILabel中的text指定范围的字体颜色
- 趋势科技搭建工控蜜罐系统
- spring整合Redis 入门例子
- Spark 中的序列化
- iOS开发之--- NSURLProtocol
- <context-param>与<init-param>的区别与作用?
- UILabel设置多种字体、颜色
- Android studio 导入项目,界面停在"Building 'project name' gradle project info"卡死
- CJSON学习笔记(二)
- Spark中的Driver本质
- 在systemd(CentOS7)自启动zookeeper
- static函数与普通函数
- 深度神经网络权值初始化的诡异问题
- 1号店交易系统架构如何向「高并发高可用」演进
- C++在线学习文档(强烈推荐)