您的位置:首页 > 产品设计 > UI/UE

【IOS类扩展之Hex值颜色转换】UIColor+Hex

2013-01-23 20:03 399 查看
#import <UIKit/UIKit.h>

@interface UIColor (Hex)

+ (UIColor *)colorWithHex:(long)hexColor;
+ (UIColor *)colorWithHex:(long)hexColor alpha:(float)opacity;

@end

#import "UIColor+Hex.h"

@implementation UIColor (Hex)

+ (UIColor*) colorWithHex:(long)hexColor;
{
return [UIColor colorWithHex:hexColor alpha:1.];
}

+ (UIColor *)colorWithHex:(long)hexColor alpha:(float)opacity
{
float red = ((float)((hexColor & 0xFF0000) >> 16))/255.0;
float green = ((float)((hexColor & 0xFF00) >> 8))/255.0;
float blue = ((float)(hexColor & 0xFF))/255.0;
return [UIColor colorWithRed:red green:green blue:blue alpha:opacity];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: