将UIColor转换为RGB值
来源:互联网 发布:深圳直播系统源码 编辑:程序博客网 时间:2024/05/18 03:24
//将UIColor转换为RGB值- (NSMutableArray *) changeUIColorToRGB:(UIColor *)color{ NSMutableArray *RGBStrValueArr = [[NSMutableArray alloc] init]; NSString *RGBStr = nil; //获得RGB值描述 NSString *RGBValue = [NSString stringWithFormat:@"%@",color]; //将RGB值描述分隔成字符串 NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "]; //获取红色值 int r = [[RGBArr objectAtIndex:1] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",r]; [RGBStrValueArr addObject:RGBStr]; //获取绿色值 int g = [[RGBArr objectAtIndex:2] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",g]; [RGBStrValueArr addObject:RGBStr]; //获取蓝色值 int b = [[RGBArr objectAtIndex:3] intValue] * 255; RGBStr = [NSString stringWithFormat:@"%d",b]; [RGBStrValueArr addObject:RGBStr]; //返回保存RGB值的数组 return [RGBStrValueArr autorelease];}