有時候美工給的是十六進制的顏色值,所以我寫了個方法來進行轉化:
// 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