label中设置某些指定的字体的属性设置(Color,Size,FontColor)

不知道大家有没有遇到要设置某些字体的颜色和大小等属性的设置,下面就让我们一起走进字体的变形王国吧!!!

1.在storyboard中拖一个控件label,拖线设置属性为:

@property (weak, nonatomic) IBOutlet UILabel *EasyLabel;

 2.在viewDidLoad中设置属性:

主要用到的一个关键字眼是attribute ,请看下面的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

// attribute:属性
// 下面两个同时存在的话第二个起作用 // self.EasyLabel.attributedText = [[NSAttributedString alloc]initWithString:@"会当凌绝顶,一览众山小"]; // self.EasyLabel.text = @"夏天"; // Label属性的设置 NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"停车坐爱枫林晚,双叶红与二月花"]; // 大小 [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:40] range:NSMakeRange(8, 7)]; // 背景颜色 [str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(7, 7)]; // 字体颜色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor purpleColor] range:NSMakeRange(4, 8)]; self.EasyLabel.attributedText = str; }

 

转载于:https://www.cnblogs.com/Ruby-Hua/p/5105597.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值