<span style="color:#009900;">UIColor+Extension.h文件</span>
//
// UIColor+Extension.h
// NothingTest
//
// Created by James on 16/3/24.
// Copyright © 2016年 Apple. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (Extension)
/**
* 返回对应的十六进制颜色
*
* @param color 十六进制颜色
*
* @return 转换后的颜色
*/
+ (instancetype)LJ_colorWithHex:(uint32_t)color;
@end
<span style="color:#009900;background-color: rgb(255, 255, 255);">UIColor+Extension.m文件</span>
<pre name="code" class="objc">//
// UIColor+Extension.m
// NothingTest
//
// Created by James on 16/3/24.
// Copyright © 2016年 Apple. All rights reserved.
//
#import "UIColor+Extension.h"
@implementation UIColor (Extension)
+ (instancetype)LJ_colorWithHex:(uint32_t)color {
/**
* color分别做&运算 分别计算RGB
*/
int red = color & 0xFF0000;
int green = color & 0x00FF00;
int blue = color & 0x0000FF;
return [UIColor colorWithRed:red / 255.0 green:green /255.0 blue:blue /255.0 alpha:1];
}
@end