给label添加不同颜色不同字体的内容
2015-07-31 13:39
267 查看
给label添加不同颜色不同字体的内容
NSMutableAttributedString *str = [[NSMutableAttributedString
alloc]
initWithString:@"oc是iOS编程的语言"];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
blueColor] range:NSMakeRange(0,2)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
redColor] range:NSMakeRange(2,3)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
greenColor] range:NSMakeRange(3,8)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Arial Hebrew"
size:30.0]
range:NSMakeRange(0,
2)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Helvetica Neue"
size:30.0]
range:NSMakeRange(2,
3)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Kohinoor Devanagari"
size:30.0]
range:NSMakeRange(3,
8)];
NSArray *names = [UIFont
familyNames];
NSLog(@"names :%@",names);
UILabel *label = [[UILabel
alloc] initWithFrame:CGRectMake(10,
300, 300,
150)];
label.backgroundColor = [UIColor
whiteColor];
label.attributedText = str;
label.numberOfLines =
0;
[self.view
addSubview:label];
NSMutableAttributedString *str = [[NSMutableAttributedString
alloc]
initWithString:@"oc是iOS编程的语言"];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
blueColor] range:NSMakeRange(0,2)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
redColor] range:NSMakeRange(2,3)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
greenColor] range:NSMakeRange(3,8)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Arial Hebrew"
size:30.0]
range:NSMakeRange(0,
2)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Helvetica Neue"
size:30.0]
range:NSMakeRange(2,
3)];
[str addAttribute:NSFontAttributeName
value:[UIFont
fontWithName:@"Kohinoor Devanagari"
size:30.0]
range:NSMakeRange(3,
8)];
NSArray *names = [UIFont
familyNames];
NSLog(@"names :%@",names);
UILabel *label = [[UILabel
alloc] initWithFrame:CGRectMake(10,
300, 300,
150)];
label.backgroundColor = [UIColor
whiteColor];
label.attributedText = str;
label.numberOfLines =
0;
[self.view
addSubview:label];
相关文章推荐
- 自动回复
- *Delphi的 Format格式化函数
- 对称加密和不对称加密原理
- django根据字符串长度截取字符串
- win10音量图标不见了怎么办?win10音量设置步骤
- Ubuntu中使用iptables
- vba excel编程三日谈(1)
- iOS8 iPAD上弹出所谓的ActionSheet
- centos下pip安装mysql_python
- angular2.0新特性总结
- xutils 配置属性优化的相关连接
- 一亿用户增长背后的架构秘密 之 腾讯微信技术架构
- vs2013+qt+opencv3.0配置
- 平分资源 Resource 解题报告
- iOS 如何获取屏幕大小
- String constants
- 某运营商网管故障报告(2013年写的)
- 如何在MacBook Pro Retina上安装Linux
- HDU 1166
- 17. Window confirm() 方法