方法1:
/********************创建.h文件
#import "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#import <UIKit/UIKit.h>
#define HXColor UIColor
#else
#import <Cocoa/Cocoa.h>
#define HXColor NSColor
#endif
@interface HXColor (HexColorAddition)
+ (HXColor *)colorWithHexString:(NSString *)hexString;
+ (HXColor *)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha;
+ (HXColor *)colorWith8BitRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue;
+ (HXColor *)colorWith8BitRed:(NSInteger)red green:(NSInteger)green blue:(NSInteger)blue alpha:(CGFloat)alpha;
@end
/********************创建.m文件
#import "HexColors.h"
@implementation HXColor (HexColorAddition)
+ (HXColor *)colorWithHexString:(NSString *)hexString
{
// Check for hash and add the missing hash
if('#' != [hexString characterAtIndex:0])
{
hexString = [NSString stringWithFormat:@"#%@", hexString];
}
CGFloat alpha = 1.0;
if (5 == h