改变字符串里面多个颜色

  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

posted on 2016-05-12 16:58  廖利君  阅读(212)  评论(0编辑  收藏  举报