十六进制的颜色值直接转为ios可用的UIColor

CSDN学院讲师招募Markdown编辑器 轻松写博文学院课程好不好你说了算!读文章说感想 获好礼企业高端研修班培训直通车

十六进制的颜色值直接转为ios可用的UIColor

分类:ios

////////////////////////////@interface UIColor (extension)+ (UIColor*) colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue;+ (UIColor*) colorWithHex:(NSInteger)hexValue;+ (NSString *) hexFromUIColor: (UIColor*) color;@end@implementation UIColor (extension)+ (UIColor*) colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue{return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0green:((float)((hexValue & 0xFF00) >> 8))/255.0blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue];}+ (UIColor*) colorWithHex:(NSInteger)hexValue{return [UIColor colorWithHex:hexValue alpha:1.0];}+ (NSString *) hexFromUIColor: (UIColor*) color {if (CGColorGetNumberOfComponents(color.CGColor) < 4) {const CGFloat *components = CGColorGetComponents(color.CGColor);color = [UIColor colorWithRed:components[0]green:components[0]blue:components[0]alpha:components[1]];}if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) != kCGColorSpaceModelRGB) {return [NSString stringWithFormat:@"#FFFFFF"];}return [NSString stringWithFormat:@"#%x%x%x", (int)((CGColorGetComponents(color.CGColor))[0]*255.0),(int)((CGColorGetComponents(color.CGColor))[1]*255.0),(int)((CGColorGetComponents(color.CGColor))[2]*255.0)];}@end

上一篇UIWebView 打开txt文档中文不乱码方法下一篇获取UIView所在的视图控制器(UIViewController)

主题推荐猜你在找

查看评论

* 以上用户言论只代表其个人观点,,不代表CSDN网站的观点或立场

核心技术类目

与其在那里苦苦挣扎,碍于面子硬撑,倒不如微笑着面对,

十六进制的颜色值直接转为ios可用的UIColor

相关文章:

你感兴趣的文章:

标签云: