OC: UIColor+MaxMethod

.h文件

#import 

@interface UIColor (MaxMethod)

+ (UIColor *)colorWithHex:(int)hex;
+ (UIColor *)colorWithHex:(int)hex alpha:(CGFloat) alpha;

@end

.m文件

#import "UIColor+MaxMethod.h"

@implementation UIColor (MaxMethod)

+ (UIColor *)colorWithHex:(int)hex {
    return [self colorWithHex:hex alpha:1.0];
}

+ (UIColor *)colorWithHex:(int)hex alpha:(CGFloat)alpha {
    CGFloat red = ((hex & 0xff0000) >> 16) / 255.0;
    CGFloat green = ((hex & 0xff00) >> 8) / 255.0;
    CGFloat blue = (hex & 0xff) / 255.0;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

@end

你可能感兴趣的:(OC: UIColor+MaxMethod)