zoukankan      html  css  js  c++  java
  • 改变字符串里面多个颜色

      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

  • 相关阅读:
    WordCount结对项目
    第一周作业:一些感想
    第一次作业
    Spring Cloud 微服务实战笔记
    解决jest处理es模块
    领域驱动设计(DDD:Domain-Driven Design)
    测试
    whistle
    日记(2018-11-07)
    ubuntu中使用机密数据Secrets
  • 原文地址:https://www.cnblogs.com/liaolijun/p/5486383.html
Copyright © 2011-2022 走看看