首页 > 其他 > 详细

同一个UILabel使用不同的大小和颜色

时间:2015-07-07 12:43:02      阅读:186      评论:0      收藏:0      [点我收藏+]

 

UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(0, 480, 300, 50)];

    label2.text = @"SD卡给你个老帅哥";

    label2.textColor = [UIColor blackColor];

    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:label2.text];

    NSInteger count = label2.text.length;

    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,4)];

    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,count-4)];

    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 4)];

    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(4, count-4)];

    label2.attributedText = str;

    [self.view addSubview:label2];

 

同一个UILabel使用不同的大小和颜色

原文:http://www.cnblogs.com/zhanghuifeng/p/4626423.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!