您的位置:首页 > 其它

给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];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: