iOS-UILabel Same Label with different font colors

iOS-UILabel Same Label with different font colors

Preface

  • UILabel has different font colors for the same Label.

As shown

- (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;
}

Guess you like

Origin blog.csdn.net/weixin_41732253/article/details/109098308