美文网首页
自定义Label指定范围的字体颜色

自定义Label指定范围的字体颜色

作者: CoderSahara | 来源:发表于2017-10-27 14:58 被阅读5次

    NSString *str1 = @"1111";
    NSString *str2 = @"2222";
    [self customizeStr:str1 colorStr:str2];
    }

    • (void)customizeStr:(NSString *)str colorStr:(NSString *)colorStr
      {
      NSString *apendStr = [NSString stringWithFormat:@"%@%@",str,colorStr];
      NSMutableAttributedString *customizeStr = [[NSMutableAttributedString alloc]initWithString:apendStr];
      NSDictionary *atr = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor greenColor]};
      NSRange colorStrRan = NSMakeRange(2, 4);
      [customizeStr setAttributes:atr range:colorStrRan];
      _colorLabel.attributedText = customizeStr;
      }

    相关文章

      网友评论

          本文标题:自定义Label指定范围的字体颜色

          本文链接:https://www.haomeiwen.com/subject/vaorpxtx.html