iOS UILabel改變指定字型大小和顏色
阿新 • • 發佈:2019-01-25
改變指定字型的顏色,range:NSMakeRange(4, 4)改變字型的位置和個數
self.enrollLabel
self.person_name
為建立UILabel的物件名字
// 改變顏色
NSMutableAttributedString *str = [[NSMutableAttributedStringalloc] initWithString:[NSStringstringWithFormat:@"一鍵報名3400元特惠班品質服務 低價學車"]];
[str addAttribute:NSForegroundColorAttributeName
self.enrollLabel.attributedText = str;
// 改變字型大小
NSMutableAttributedString *str = [[NSMutableAttributedStringalloc] initWithString:@"一鍵報名3400元特惠班品質服務 低價學車"];
[str addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15] range
[str addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:14] range:NSMakeRange(6,9)];
self.person_name.attributedText = str;