美文网首页
iOS_Label 中显示不同的颜色和字体

iOS_Label 中显示不同的颜色和字体

作者: 青葱烈马 | 来源:发表于2016-09-22 13:50 被阅读25次
        NSString *usedStr = [NSString stringWithFormat:@"满%@元可用",[couponData objectForKey:@"minimum_payment_amount"]];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:usedStr];
        // 设置字体颜色
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,1)];
        [str addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0x19898e) range:NSMakeRange(1,3)];
        [str addAttribute:NSForegroundColorAttributeName value:HEXCOLOR(0x26bbc8) range:NSMakeRange(4, 3)];
        // 设置字体
        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0,1)];
        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(1,3)];
        [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(4,3)];
        self.couponUsedLbl.attributedText = str;
    
    Paste_Image.png

    相关文章

      网友评论

          本文标题:iOS_Label 中显示不同的颜色和字体

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