UILabel *countLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 50)];
countLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:countLabel];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"1234567890"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(5,5)];
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0,5)];
[str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(5,5)];
countLabel.attributedText = str;
自定义UILabel中的text格式(字体字号颜色等)
最新推荐文章于 2019-09-17 09:22:10 发布