NSString * noticeStr = [NSString stringWithFormat:@"将获得¥%@",[YZHttpmanager positiveFormat:amountStr]];
NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@".",@",",@"¥"];
NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:noticeStr];
for (int i = 0; i < noticeStr.length; i ++) {
//这里的小技巧,每次只截取一个字符的范围
NSString *a = [noticeStr substringWithRange:NSMakeRange(i, 1)];
//判断装有0-9的字符串的数字数组是否包含截取字符串出来的单个字符,从而筛选出符合要求的数字字符的范围NSMakeRange
if ([number containsObject:a]) {
[attributeString setAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFF5A00),NSFontAttributeName:[UIFont boldSystemFontOfSize:25],NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:0]} range:NSMakeRange(i, 1)];
}
}
amountlab.attributedText=attributeString;
网友评论