• 改变字符串里面多个颜色


      NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"作品:%@",data[@"works_num"]]];

        NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@":"].location);

        [noteStr addAttribute:NSForegroundColorAttributeName value:COLOR_9999COLOR range:redRange];

        [_productLabel setAttributedText:noteStr] ;

        [_productLabel sizeToFit];

     //获取内容高度 判断高度的大小 改变其他控件的坐标

        CGFloat heigh1 = [Unit heightWithString:_synopsisLab.text

                                           font:_synopsisLab.font

                             constrainedToWidth:_synopsisLab.width];

        _synopsisLab.height = heigh1;

        synopsisBackView.height = _synopsisLab.height+73;

    NSString *strStaus = @"这里是需要修改的内容";

    NSString *str = [NSString stringWithFormat:@"天气:%@  ",,strStaus];

    NSMutableAttributedString *attrDescribeStr = [[NSMutableAttributedString alloc] initWithString:str];

    [attrDescribeStr addAttribute:NSForegroundColorAttributeName

    value:[UIColor orangeColor]

    range:[str rangeOfString:strStaus]];

    self.myNameLable.attributedText = attrDescribeStr;

     最后是strStaus里面的字体颜色变成orange

  • 相关阅读:
    java 求两个数最大值
    java 加法运算
    javs switch 语句
    git合并分支成功,但是push失败(remote: GitLab: You are not allowed to push code to protected branches on this project.)
    python 获取日期以及时间
    1713
    linux shell脚本中的延时
    java 类的继承
    Python3 使用企业微信 API 发送消息
    java if 条件语句
  • 原文地址:https://www.cnblogs.com/liaolijun/p/5486383.html
Copyright © 2020-2023  润新知