UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0.065*UIScreenSize.width, backBtn.frame.origin.y + backBtn.frame.size.height, UIScreenSize.width - 0.12*UIScreenSize.width, 0.14*UIScreenSize.height)];
label1.numberOfLines = 0;
label1.font = [UIFont boldSystemFontOfSize:14];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"请慎用加息卡,加息期间账户所有资金(包括新的投资资金)将被冻结,都不可提现,直至加息卡使用结束。"];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, str.length)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(33, 4)];
label1.attributedText = str;
[navUI addSubview:label1];
效果图如下:
PS: 另附上别的修改的属性!
1. 改变字体类型或者字体大小
NSString *str = [NSString stringWithFormat:@"%@",cstr];
NSMutableAttributedString *tmpStr = [[NSMutableAttributedString alloc]initWithString:str];
[tmpStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, str.length-1)];
2. 添加下划线
self.externBtn = [[UIButton alloc]init];
NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"跳过此步骤"];
NSRange titleRange = {0,[title length]};
[title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
[title addAttribute:NSForegroundColorAttributeName value:DefaultColor range:titleRange];
[self.externBtn setAttributedTitle:title forState:UIControlStateNormal];
还有一些别的属性