iOS在一个label中显示不同颜色的字体
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"set background color with button"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,2)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0] range:NSMakeRange(0, 5)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0] range:NSMakeRange(6, 12)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0] range:NSMakeRange(19, 6)];
Label.attributedText = string;
[self.view addSubview:Label];
最新文章
- [Android]AndroidInject增加sqlite3数据库映射注解(ORM)
- monkeyrunner之环境搭建及实例(三)
- [Linux]CentOS下安装和使用tmux
- Leetcode-121 Best Time to Buy and Sell Stock
- 【转】mac/linux终端光标的快捷键操作
- CentOS 7 firewalld使用简介
- FPGA控制HC595
- 剑指Offer45 约瑟夫环
- Asp.net主题(theme)和皮肤(skin)的使用
- 杭电dp题集,附链接还有解题报告!!!!!
- 2108 ACM 向量积 凹凸
- centos6.5安装jdk(解压tar.gz)
- C# 随机四位数验证码
- myeclipse部署项目的时候报No projects are available for deployment to this server但是项目明明存在
- input 内容改变的触发事件
- 1. 通俗易懂解释知识图谱(Knowledge Graph)
- 双机\RAC\Dataguard的区别
- SYS_R12 MOAC多组织底层技术实现技术分析(Oracle VPD) (案例)
- 【SP2713 GSS4 - Can you answer these queries IV】 题解
- 玩一下易语言 ";和";字有多种读音,注定了它的重要性!!
热门文章
- android源码mk文件里的TARGET_OUT指向哪里?
- 创建微服务项目后,在谷歌、Safari等浏览器下无法访问的具体原因
- hdu4888 多校B 最大流以及最大流唯一判断+输出方案
- Wannafly挑战赛11 D 题 字符串hash + 卡常
- log4j配置(转载)
- spark学习(六)Java版RDD基本的基本操作
- spark学习(五)总结及其demo
- FFT/NTT模板 既 HDU1402 A * B Problem Plus
- TreeView 与 ListView
- 【POJ 3292】 Semi-prime H-numbers