NSMutableAttributedString *your_string = [[NSMutableAttributedString alloc] initWithString:@"Today is Wednesday !"];
[your_string addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0,5)];
[your_string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,2)];
[your_string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(9,10)];
[your_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"STHeitiSC-Light" size:20.0] range:NSMakeRange(0, 5)];
[your_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(6, 2)];
[your_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:20.0] range:NSMakeRange(9, 10)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 320 , 100)];
attrLabel.attributedText = your_string;
attrLabel.numberOfLines = 0;
[self.view addSubview:label];
UILabel 显示多种字体和颜色
最新推荐文章于 2017-08-24 21:00:15 发布