现在的位置: 首页 > 综合 > 正文

//将UIColor转换为RGB值

2013年09月22日 ⁄ 综合 ⁄ 共 750字 ⁄ 字号 评论关闭

//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
];

}

抱歉!评论已关闭.