label显示不同大小、颜色的字符串
2016-04-09 13:57
369 查看
UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(20,
400, 200,
30)];
//定义字符串
NSMutableAttributedString类型可以方便改变特定的字符
NSMutableAttributedString *attributeString =
[[NSMutableAttributedString alloc]
initWithString:@"This is
xiaoming"];
//前2个文字是红色
[attributeString addAttributes:@{NSForegroundColorAttributeName:[UIColor
redColor],NSFontAttributeName:[UIFont systemFontOfSize:30]}
range:NSMakeRange(0,
1)];
[attributeString addAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}
range:NSMakeRange(2,
10)];
//设置属性文字
l.attributedText = attributeString;
[self.view addSubview:l];
400, 200,
30)];
//定义字符串
NSMutableAttributedString类型可以方便改变特定的字符
NSMutableAttributedString *attributeString =
[[NSMutableAttributedString alloc]
initWithString:@"This is
xiaoming"];
//前2个文字是红色
[attributeString addAttributes:@{NSForegroundColorAttributeName:[UIColor
redColor],NSFontAttributeName:[UIFont systemFontOfSize:30]}
range:NSMakeRange(0,
1)];
[attributeString addAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}
range:NSMakeRange(2,
10)];
//设置属性文字
l.attributedText = attributeString;
[self.view addSubview:l];
相关文章推荐
- iOS常见锁对象
- CALayer简单内容
- poj 2186 Popular Cows 强连通分量分解
- 利用广度优先搜索求最短路径
- OpenCV学习之2
- 代码过千行的感想
- 【2016.4.6】结对编程 终章 THE END
- sqlldr入库4G大小txt文件
- ActiveX开发流程
- GCD几种简单用法
- 谷歌新书:SRE
- [IO]——打印流
- 求两个整数之间的汉明距离---Salem
- 【UFLDL-exercise3&4-PCA and Whitening】
- 第七周上机实践项目-项目一-线段类-成员函数
- Unity组件的基类单例模式
- MongoDB shell脚本 自动添加权限与账号密码
- “Enterprise Architect”和数据库的不解之缘
- 以对象的方式来访问xml数据表(三)
- 自定义cell中的按钮点击事件