博主以前写过一篇同一段文字显示不同颜色:
http://blog.csdn.net/codingfire/article/details/50395838
今天再提供一种方法,其实都是一样的,不过这次同一段文字显示不同颜色和字体大小的文字:
//可提现金额 UILabel *tixianLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 60, 300, 20)]; tixianLabel.text = @"当前可提现金额0.00元"; tixianLabel.textAlignment = NSTextAlignmentLeft; tixianLabel.font = [UIFont systemFontOfSize:14]; tixianLabel.textColor = [UIColor colorWithRed:0.27f green:0.28f blue:0.28f alpha:1.00f]; [self.view addSubview:tixianLabel]; NSString *testStr = @"当前可提现金额3000.00元"; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:testStr]; [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.27f green:0.61f blue:1.00f alpha:1.00f] range:NSMakeRange(7,testStr.length - 8)]; [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(7,testStr.length - 8)]; tixianLabel.attributedText = str;
其实原理都是通过Attribute来实现的,具体的看看代码。