我试着评价这句话:
<font color="0.839216,0.839216,0.839216" strokeColor="none" size="35" face="Avenir-Book">
我需要提取颜色属性的 3 个浮点值
使用此代码:
NSRegularExpression* colorRegex = [[[NSRegularExpression alloc] initWithPattern:@"color=([0-9]+),([0-9]+),([0-9]+)" options:0 error:NULL] autorelease];
[colorRegex enumerateMatchesInString:tag options:0 range:NSMakeRange(0, [tag length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
NSNumber *redComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range] floatValue] ];
NSNumber *greenComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range ] floatValue] ];
NSNumber *blueComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range] floatValue] ];
self.color=[[UIColor alloc] initWithRed:redComponent.floatValue green:greenComponent.floatValue blue:blueComponent.floatValue alpha:1];
NSLog(@"color %@,%@,%@",redComponent,greenComponent,blueComponent);
我测试了几个正则表达式,但我没有成功,有人可以帮助我吗?