改变UILable里面文字的大小和颜色

UILabel *lb = [[UILabel alloc]init];

        NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc]initWithString:@"我中奖了,700多万哈哈,你信吗?"];

        [attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 5)];

        [attriStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 5)];

        [attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(10, 7)];

        

        NSMutableAttributedString *attrMutMsg = [[NSMutableAttributedString alloc] initWithString:@"信不信由你,反正是真的!" attributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:[UIColor yellowColor]}];

        [attriStr appendAttributedString:attrMutMsg];

        lb.attributedText = attriStr;

posted @ 2016-03-01 15:56  LiLM  阅读(269)  评论(0编辑  收藏  举报