zoukankan      html  css  js  c++  java
  • 利用NSMutableAttributedString实现label上字体大小颜色行间距的改变

            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

    //     使用斜杠n是字体显示为两行

            label.text = @"随堂测验 (学习完成后,开始测试)";

            label.font =  [UIFont systemFontOfSize:10];

    //     使用换行符号切莫忘记写这句

            label.numberOfLines = 0;

            label.textColor = [UIColor hexChangeFloat:@"A5A5A5"];

    //        利用属性字符串修改字体大小  颜色

            NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc] initWithString:label.text];

     

            [AttributedStr addAttribute:NSForegroundColorAttributeName

                                  value:[HuConfigration uiColorFromString:@"#D3D3D3"]

                                  range:NSMakeRange(0, 4)];

            [AttributedStr addAttribute:NSFontAttributeName

                                  value:[UIFont customFontSize:18]

                                  range:NSMakeRange(0 , 4)];

    //        修改行间距

            NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];

            [paragraphStyle setLineSpacing:4];

            [AttributedStr addAttribute:NSParagraphStyleAttributeName

                                  value:paragraphStyle

                                  range:NSMakeRange(0, [label.text length])];

           label.attributedText = AttributedStr;

     

            label.textAlignment = NSTextAlignmentCenter;

            [self addSubview:label];

     效果图:

     

     

  • 相关阅读:
    CentOS7 yum方式安装MariaDB 10.2.13-1
    追踪go语言(golang)的新版本新特性【摘抄】
    基于Jersey使用Session
    Netbeans 8.1 检测不到Tomcat8.5.3以上版本已经启动的Bug
    CentOS6上实现Tomcat8 service启动,并查看status
    【转帖】oracle数据类型和对应的java类型
    css文件的MIME错误引发的Jquery Mobile绘制错误
    Elasticsearch index fields 重命名
    oozie调度sqoop Job 数据库密码无法保存
    Java——安全地停止线程
  • 原文地址:https://www.cnblogs.com/huanghaipo/p/6933923.html
Copyright © 2011-2022 走看看