iOS 颜色转换 UIColor 和 HEX

+(NSInteger)colorToHex:(UIColor*)color{
    CGFloat r,g,b,a;
    [color getRed:&r green:&g blue:&b alpha:&a];
    return (int)(r*255)<<16 | (int)(g*255)<<8 | (int)(b*255);
}

+(UIColor*)hexToColor:(NSInteger)hex{
    return [UIColor colorWithRed:(hex>>16&0xff)/255.f green:(hex>>8&0xff)/255.f blue:(hex&&0xff)/255.f alpha:1];
}

你可能感兴趣的:(iOS 颜色转换 UIColor 和 HEX)