Label中某几个字符颜色大小不同

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100, 10, 200, 100)];
    int i=arc4random()%100;
    NSString *str1=@"本期参与:";
    NSString *str2=[NSString stringWithFormat:@"%d",i];
    NSString *str3=@"人次";
    NSString *contentStr=[NSString stringWithFormat:@"%@%@%@",str1,str2,str3];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:contentStr];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5,str2.length )];
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:25] range:NSMakeRange(0, str2.length)];
    label.attributedText = str;
    [self.view addSubview:label];

运行结果:



转载请注明出处http://blog.csdn.net/chen_gp_x

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 撸撸猫 设计师: 设计师小姐姐
应支付0元
点击重新获取
扫码支付

支付成功即可阅读