您的位置:首页 > 产品设计 > UI/UE

iOS UILabel改变指定字体大小和颜色

2016-12-13 16:32 585 查看
改变指定字体的颜色,range:NSMakeRange(4, 4)改变字体的位置和个数

self.enrollLabel 

self.person_name

为创建UILabel的对象名字

// 改变颜色

NSMutableAttributedString *str = [[NSMutableAttributedString
alloc]
initWithString:[NSString
stringWithFormat:@"一键报名3400元特惠班
品质服务        低价学车"]];

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

  self.enrollLabel.attributedText
= str;

       



// 改变字体大小

 NSMutableAttributedString *str  = [[NSMutableAttributedString
alloc]
initWithString:@"一键报名3400元特惠班 品质服务
       低价学车"];

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

 [str addAttribute:NSFontAttributeName
value:[UIFont
systemFontOfSize:14]
range:NSMakeRange(6,9)];

 self.person_name.attributedText = str;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: