本文可以找个一个label 中的数字和其他类型混排中的数字
- (NSMutableAttributedString *)getPhoneFromData:(NSString *)data{
NSString *phone = data;
NSString *temp1 =[[NSString alloc]init];
NSString *strNew = [[NSString alloc]init];
NSMutableArray *arrr = [[NSMutableArray alloc]init];
for (int i = 0; i < phone.length; i++) {
temp1 =[phone substringWithRange:NSMakeRange(i, 1)];
if ([temp1 isEqualToString:@"0"]||
[temp1 isEqualToString:@"1"]||
[temp1 isEqualToString:@"2"]||
[temp1 isEqualToString:@"3"]||
[temp1 isEqualToString:@"4"]||
[temp1 isEqualToString:@"5"]||
[temp1 isEqualToString:@"6"]||
[temp1 isEqualToString:@"7"]||
[temp1 isEqualToString:@"8"]||
[temp1 isEqualToString:@"9"]) {
NSString *str = [NSString stringWithFormat:@"%d",i];
[arrr addObject:str];
};
}
NSLog(@"%@",phone);
NSLog(@"记录数字位数%@",arrr);
NSString *kaishi =[[NSString alloc]init];
NSString *jieshu = [[NSString alloc]init];
kaishi = [NSString stringWithFormat:@"%@",arrr[0]];
NSUInteger int1 = arrr.count;
jieshu = [NSString stringWithFormat:@"%@",arrr[int1-1]];
NSLog(@"%@-%@",kaishi,jieshu);
int ks=[kaishi intValue];
int js =[jieshu intValue];
int zs = js - ks ;
NSLog(@"%d",zs);
UILabel *testLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 60 , 320, 30)];
testLabel.backgroundColor = [UIColor lightGrayColor];
testLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:testLabel];
NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:phone];
[AttributedStr addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:16.0]
range:NSMakeRange(ks+1, zs+1)];
[AttributedStr addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(ks, zs+1)];
return AttributedStr;
}