UILabel设置字体不同颜色
1 |
self.title = @ "For iOS 6 & later" ; |
2 |
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@ "Using NSAttributed String" ]; |
3 |
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)]; |
4 |
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)]; |
5 |
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)]; |
6 |
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@ "Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)]; |
7 |
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@ "HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)]; |
8 |
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@ "Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)]; |
9 |
attrLabel.attributedText = str; |