有时候美工给的是十六进制的颜色值,所以我写了个方法来进行转化:
// UIColor+UIColor.h
#import <UIKit/UIKit.h>
@interface UIColor (UIColor)
+ (UIColor *)colorWithHexValue:(NSUInteger)hexValue alpha:(CGFloat)alpha;//eg. self.window.backgroundColor = [UIColor colorWithHexValue:0x123456 alpha:0.8];
@end
#import "UIColor+UIColor.h"
@implementation UIColor (UIColor)
+ (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