iOS自写cmyk颜色格式转换成RGB格式

- (UIColor *)getColor:(NSString *)hexColor

{
    float red,green,blue;
    int length = hexColor.length;
    red = [self getRGBvalue:[hexColor substringWithRange:NSMakeRange(1,length-5)]];
    green = [self getRGBvalue:[hexColor substringWithRange:NSMakeRange(length-4, 2)]];
    blue = [self getRGBvalue:[hexColor substringWithRange:NSMakeRange(length-2,2)]];
    return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f];
}
- (float)getRGBvalue:(NSString*)color
{
    NSString *tenV = [color substringWithRange:NSMakeRange(0, color.length-1)];
    NSString *unitV = [color substringWithRange:NSMakeRange(color.length-1, 1)];
    return [self getV:tenV]*16+[self getV:unitV];
}
- (int)getV:(NSString *)str
{
    int iV = 0;
    if ([str isEqualToString:@"A"]||[str isEqualToString:@"a"])
    {
        iV = 10;
    }else
    if ([str isEqualToString:@"B"]||[str isEqualToString:@"b"])
    {
        iV = 11;
    }else
    if ([str isEqualToString:@"C"]||[str isEqualToString:@"c"])
    {
        iV = 12;
    }else
    if ([str isEqualToString:@"D"]||[str isEqualToString:@"d"])
    {
        iV = 13;
    }else
    if ([str isEqualToString:@"E"]||[str isEqualToString:@"e"])
    {
        iV = 14;
    }else
    if ([str isEqualToString:@"F"]||[str isEqualToString:@"f"])
    {
        iV = 15;
    }
    else
    {
        iV = [str intValue];
    }
    return iV;
}
展开阅读全文

没有更多推荐了,返回首页