在开发的过程中 UI给我们的颜色很可能不是RGB的 可能会是一个十六进制的,下面写的而一个类别实现十六进制的颜色转化


UIColor+HexadecimalColor.h

#import <UIKit/UIKit.h>

@interface UIColor (HexadecimalColor)
+ (UIColor *)colorWithHexValue:(NSUInteger)hexValue alpha:(CGFloat)alpha;//eg. self.window.backgroundColor = [UIColor colorWithHexValue:0x123456 alpha:0.8];
@end

UIColor+HexadecimalColor.m

#import "UIColor+HexadecimalColor.h"

@implementation UIColor (HexadecimalColor)

+ (UIColor *)colorWithHexValue:(NSUInteger)hexValue alpha:(CGFloat)alpha
{
    return [UIColor colorWithRed:((hexValue >> 16) & 0x000000FF)/255.0f
                           green:((hexValue >> 8) & 0x000000FF)/255.0f
                            blue:((hexValue) & 0x000000FF)/255.0
                           alpha:alpha];
}
@end