您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页在一个Label中显示不同的字体颜色

在一个Label中显示不同的字体颜色

来源:化拓教育网

UILabel* noteLabel = [[UILabel alloc] init];

noteLabel.frame = CGRectMake(0, 100, 200, 100);

noteLabel.textColor = [UIColor blackColor];

NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:@”1111:2222”];

NSRange redRange = NSMakeRange(0, [[noteStr string] rangeOfString:@”:”].location);

[noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];

[noteLabel setAttributedText:noteStr] ;

[noteLabel sizeToFit];

[self.view addSubview:noteLabel];

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务