zoukankan      html  css  js  c++  java
  • iOS在一个label中显示不同颜色的字体

    UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 30)];

        

        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"set background color with button"];

        [string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,2)];

        [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];

        [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];

        [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:17.0] range:NSMakeRange(0, 5)];

        [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17.0] range:NSMakeRange(6, 12)];

        [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:17.0] range:NSMakeRange(19, 6)];

        Label.attributedText = string;

        [self.view addSubview:Label];

     

     

       效果图 :  set background color with button
  • 相关阅读:
    vim编辑器和bash算术运算入门
    vim编辑器
    egrep及文本处理工具
    grep与基本正则表达式
    bash脚本编程基础及配置文件
    博客开通了
    测试用例考虑因素
    地图测试点的总结
    app测试的case点(2)
    App 99.9%稳定
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/9208923.html
Copyright © 2011-2022 走看看