您的位置:首页 > 其它

设置label上文字显示不同大小、颜色、字体类型

2017-10-31 10:26 1016 查看
bottomS = @"注意:\n\n1.所有所有;\n\n2.标余额;\n\n3.不可退款。";

NSMutableAttributedString *noteStr = [[NSMutableAttributedStringalloc]
initWithString:bottomS];

    // 需要改变的第一个文字的位置

    NSUInteger firstLoc = [[noteStrstring]
rangeOfString:@"3"].location;

    // 需要改变的最后一个文字的位置

    NSUInteger secondLoc = [[noteStrstring]
rangeOfString:@"。"].location+1;

    // 需要改变的区间

    NSRange range =
NSMakeRange(firstLoc, secondLoc - firstLoc);

    // 改变颜色

    [noteStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]
range:range];

    // 改变字体大小及类型

    //    [noteStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-BoldOblique" size:27] range:range];

    // 为label添加Attributed

    [self.bottomTextsetAttributedText:noteStr];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐