iOS-UILabel同一个Label 不同字体颜色

iOS-UILabel同一个Label 不同字体颜色

前言

  • UILabel同一个Label 不同字体颜色。

如图

- (UILabel *)tipsLabel {
    
    
    if(_tipsLabel == nil) {
    
    
        _tipsLabel = [[UILabel alloc]init];
        _tipsLabel.font = [UIFont systemFontOfSize:HNWidth(14)];
        _tipsLabel.textAlignment = NSTextAlignmentLeft;
        _tipsLabel.textColor = HN_Color_Hex(#18F8F5);
        //不同颜色
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:NSLocalizedString(@"kBaseVideoCallViewOpengirlturned", nil)];
        NSRange range2 = [[str string] rangeOfString:NSLocalizedString(@"kBaseVideoCallViewOpengirl", nil)];
        [str addAttribute:NSForegroundColorAttributeName value:HN_Color_Hex(#FCD126) range:range2];
        _tipsLabel.attributedText = str;
    }
    return _tipsLabel;
}

猜你喜欢

转载自blog.csdn.net/weixin_41732253/article/details/109098308