同一个label设置不同颜色文字

  • (void)setupDiffColorLabel:(UILabel )label WithTitle:(NSString )title WithSeparateString:(NSString )separate WithLeadColor: (UIColor )LeadColor WithTrailColor :(UIColor *)TrailColor
    {
    label.text = title;
    label.textColor = LeadColor;
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:separate].location);
    [noteStr addAttribute:NSForegroundColorAttributeName value:TrailColor range:redRange];
    [label setAttributedText:noteStr];
    }

你可能感兴趣的:(同一个label设置不同颜色文字)