zoukankan      html  css  js  c++  java
  • iOS开发实现Label中多颜色多字体

      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)];

        label.textColor = wordGaryColor;  //未专门设置的字体颜色

        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"公司简介:发挥收到后即可圣诞节快发吧士大夫深刻的房价高速度开放和山东矿机山东科技楼粉红是大家分工"];

        [str addAttribute:NSForegroundColorAttributeName value:commonColor range:NSMakeRange(0,5)];

       [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
       [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
       [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:19] range:NSMakeRange(0, 5)];
       [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];
       [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];

        label.attributedText = str;

        [self.view addSubview:label];

  • 相关阅读:
    ASP.NET中级学习3
    C#面向对象学习笔记
    Javascript学习笔记
    FormView控件使用
    ASP.NET初级学习
    ListView控件是使用
    Java NIO 学习笔记一
    堆栈和托管堆 c#
    安装php7.2并且整合nginx且分开部署
    Python 安装requests和MySQLdb
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5161209.html
Copyright © 2011-2022 走看看