UILabel显示不同颜色文字。
2014-01-22 12:45
344 查看
NSString *attentionStr =
NSLocalizedStringFromTable(@"zhuyi",@"InfoPlist",@"When you press “Register” you agree with our Privacy policy
(http://www.polar.ru/politics) and Terms of service (http://www.polar.ru/services");
CGSize fontSize = [attentionStr
sizeWithFont:FONT24];
//注意
UILabel *attentionLabel = [[UILabel
alloc] initWithFrame:CGRectMake(10,
sumNameTextField.frame.size.height+sumNameTextField.frame.origin.y+10,
300, 100)];
attentionLabel.numberOfLines = fontSize.width>1125?5:3;
attentionLabel.lineBreakMode =
NSLineBreakByWordWrapping;
attentionLabel.font =
FONT24;
attentionLabel.backgroundColor =
CLEARCOLOR;
attentionLabel.textColor =
TitleColor;
attentionLabel.textAlignment =
NSTextAlignmentCenter;
[registerScrollView
addSubview:attentionLabel];
NSMutableAttributedString *str = [[NSMutableAttributedString
alloc] initWithString:attentionStr];
int a = [[str
string] rangeOfString:@"("].location;
int b = [[str
string] rangeOfString:@")"].location;
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
orangeColor] range:NSMakeRange(a,b-a+1)];
int length2 = [str
string].length-b-1;
int c = [[str
string] rangeOfString:@"("
options:NSCaseInsensitiveSearch
range:NSMakeRange(b+1, length2)].location;
int d = [[str
string] rangeOfString:@")"
options:NSCaseInsensitiveSearch
range:NSMakeRange(b+1, length2)].location;
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
orangeColor] range:NSMakeRange(c,d-c+1)];
attentionLabel.attributedText = str;
效果如图:
NSLocalizedStringFromTable(@"zhuyi",@"InfoPlist",@"When you press “Register” you agree with our Privacy policy
(http://www.polar.ru/politics) and Terms of service (http://www.polar.ru/services");
CGSize fontSize = [attentionStr
sizeWithFont:FONT24];
//注意
UILabel *attentionLabel = [[UILabel
alloc] initWithFrame:CGRectMake(10,
sumNameTextField.frame.size.height+sumNameTextField.frame.origin.y+10,
300, 100)];
attentionLabel.numberOfLines = fontSize.width>1125?5:3;
attentionLabel.lineBreakMode =
NSLineBreakByWordWrapping;
attentionLabel.font =
FONT24;
attentionLabel.backgroundColor =
CLEARCOLOR;
attentionLabel.textColor =
TitleColor;
attentionLabel.textAlignment =
NSTextAlignmentCenter;
[registerScrollView
addSubview:attentionLabel];
NSMutableAttributedString *str = [[NSMutableAttributedString
alloc] initWithString:attentionStr];
int a = [[str
string] rangeOfString:@"("].location;
int b = [[str
string] rangeOfString:@")"].location;
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
orangeColor] range:NSMakeRange(a,b-a+1)];
int length2 = [str
string].length-b-1;
int c = [[str
string] rangeOfString:@"("
options:NSCaseInsensitiveSearch
range:NSMakeRange(b+1, length2)].location;
int d = [[str
string] rangeOfString:@")"
options:NSCaseInsensitiveSearch
range:NSMakeRange(b+1, length2)].location;
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor
orangeColor] range:NSMakeRange(c,d-c+1)];
attentionLabel.attributedText = str;
效果如图:
相关文章推荐
- 渲染自定义格式字符串的UILabel(同一个lable的不同文字可以显示不同的颜色和字体)
- iOS 在一个UILabel里显示不同的颜色,给文字加下划线
- iOS 在一个UILabel里显示不同的颜色,给文字加下划线
- ios UILabel显示不同颜色的文字
- iOS UILabel显示文字设置不同的颜色以及行间距
- 设置UIButton中的文字和图片,设置UILabel的文在显示不同颜色
- 设置UIButton中的文字和图片,设置UILabel的文在显示不同颜色
- UIlabel 文字颜色不同
- Android编程实现控件不同状态文字显示不同颜色的方法
- Mac 终端—不同文件不同颜色显示,提示文字
- iOS 在UILabel显示不同的字体和颜色
- iOS 在UILabel显示不同的字体和颜色
- iOS 在UILabel显示不同的字体和颜色
- C# richTextBox显示不同文字颜色
- UILabel显示不同的字体和颜色
- iOS 在UILabel显示不同的字体和颜色
- iOS 同一段文字显示不同颜色
- iOS 在UILabel显示不同的字体和颜色
- 一个UILabel不同部分显示不同颜色
- iOS 在UILabel显示不同的字体和颜色