UILabel设置多种字体、颜色
2015-07-26 15:07
363 查看
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String,try your best to test attributed string text"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(19, 6)];
UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 320 - 40, 90)];
attrLabel.attributedText = str;
attrLabel.numberOfLines = 0;
[self.view addSubview:attrLabel];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial" size:30.0] range:NSMakeRange(19, 6)];
UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 320 - 40, 90)];
attrLabel.attributedText = str;
attrLabel.numberOfLines = 0;
[self.view addSubview:attrLabel];
相关文章推荐
- HDU 1047 Integer Inquiry【大数】
- [多校2015.01.1010 容斥+迭代] hdu 5297 Y sequence
- 01-复杂度2. Maximum Subsequence Sum (25)
- iOS Human Interface Guidelines(原创翻译)第三章
- hdu 1941 Justice League 无向完全图
- UVa 11235 FrequentValues(RMQ)
- iOS学习之UIPickerView控件的关联选择
- 使用segue时如何实现login的判断
- iOS UINavigationController与UITabBarController的组合使用
- UINavigationController within a UITabBarController, setting the navig
- 在UINavigationController 中增加 UITabBarController 然后设置navigatio
- 使用segue时实现login的判断,判断正确了才切换到下个视图
- Demo and Test Setup Guide - OFBiz Project Administration Workspac
- hdu1005 Number Sequence
- 用Android手机通过蓝牙模块HC-06连接Arduino串口输出
- BestCoder 1st Anniversary ($) 第三题 Sequence
- Sequence operation
- poj 2749 Building roads 【2-sat + 二分】【建图较复杂】【好题】
- 2015 Multi-University Training Contest 2 hdu 5306 Gorgeous Sequence
- html之marquee详解