//将UIColor转换为RGB值

//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:0] intValue] * 255;

    RGBStr = [NSString stringWithFormat:@"%d",r];

    [RGBStrValueArr addObject:RGBStr];

    //获取绿色值

    int g = [[RGBArr objectAtIndex:1] intValue] * 255;

    RGBStr = [NSString stringWithFormat:@"%d",g];

    [RGBStrValueArr addObject:RGBStr];

    //获取蓝色值

    int b = [[RGBArr objectAtIndex:2] intValue] * 255;

    RGBStr = [NSString stringWithFormat:@"%d",b];

    [RGBStrValueArr addObject:RGBStr];

    //返回保存RGB值的数组

    return [RGBStrValueArr autorelease];

}

你可能感兴趣的:(//将UIColor转换为RGB值)