1. 程式人生 > >UILabel設定一段文字不同顏色和不同大小

UILabel設定一段文字不同顏色和不同大小

//設定不同字型顏色

-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor

{

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

//設定字號

    [str addAttribute:NSFontAttributeName value:font range:range];

//設定文字顏色

    [str addAttribute:NSForegroundColorAttributeNamevalue:vaColor range:range];

    labell.attributedText = str;

}