码迷,mamicode.com
首页 > 其他好文 > 详细

在一个Label上设置多种颜色字体

时间:2015-06-26 17:35:27      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

                                           技术分享

               

 1 #import "AppDelegate.h"
 2 
 3 @interface AppDelegate ()
 4 
 5 @end
 6 
 7 @implementation AppDelegate
 8 
 9 
10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
11     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
12     
13     // Override point for customization after application launch.
14     self.window.backgroundColor = [UIColor whiteColor];
15     
16     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 200)];
17     // 设置多属性字符串
18     NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using   NSAttributed   String"];
19     // 设置蓝色字体,范围(0, 5),其中空格也算一个占位符
20     [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 5)];
21     // 设置红色字体,范围(6, 12),其中空格也算一个占位符
22     [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6, 12)];
23     // 设置红色字体,范围(13, 6),其中空格也算一个占位符
24     [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(13, 6)];
25     
26     label.attributedText = str;
27     
28     [self.window addSubview:label];
29     [self.window makeKeyAndVisible];
30     return YES;
31 }
32 
33 @end

 

在一个Label上设置多种颜色字体

标签:

原文地址:http://www.cnblogs.com/lantu1989/p/4602523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!