zoukankan      html  css  js  c++  java
  • 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; }
  • 相关阅读:
    luogu P1613 跑路
    luogu P2047 社交网络
    luogu P2740 [USACO4.2]草地排水Drainage Ditches
    「字典树」最大异或对
    「贪心」耍杂技的牛
    「贪心」士兵
    「贪心」糖果传递
    「几何」[USACO12DEC]疯狂的栅栏Crazy Fences
    「LCA」[USACO10HOL]牛的政治Cow Politics
    「二分答案 + 前缀和」防线
  • 原文地址:https://www.cnblogs.com/Ruby-Hua/p/5105597.html
Copyright © 2011-2022 走看看