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

 

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];

 

posted on 2015-07-07 11:19  殇_了  阅读(246)  评论(0编辑  收藏  举报

导航