UIbutton 换行且不同字体大小颜色设置

  • (NSAttributedString *)getStrWithSring:(NSString *)leftStr rightStr:(NSString *)rightStr leftColor:(UIColor *)leftColor rightColor:(UIColor *)rightColor {
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n",leftStr]];
    [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFangSC-Medium" size:18.0] range:NSMakeRange(0, str.length)];
    [str addAttribute:NSForegroundColorAttributeName value:leftColor range:NSMakeRange(0, str.length)];

    NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",rightStr]];
    [str1 addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"PingFangSC-Light" size:12.0] range:NSMakeRange(0, str1.length)];
    [str1 addAttribute:NSForegroundColorAttributeName value:rightColor range:NSMakeRange(0, str1.length)];

    [str appendAttributedString:str1];
    return str;
    }

你可能感兴趣的:(UIbutton 换行且不同字体大小颜色设置)