// // UIColor+KXHex.m // QBCS // // Created by kuxuan on 2017/6/6. // Copyright © 2017年 kuxuan. All rights reserved. // #import "UIColor+KXHex.h" @implementation UIColor (KXHex) + (instancetype)themeColor { return [self KXColorWithHex:0x6436FE]; } + (instancetype)themeColorWithAlpha{ return [self KXColorWithHex:0x6436FE alpha:0.4]; } +(instancetype)lineColor { return [self KXColorWithHex:0xdddddd]; } +(instancetype)lineColor1 { return [self KXColorWithHex:0xd9d9d9]; } +(instancetype)background { return [self KXColorWithHex:0xefeff5]; } +(instancetype)baseColor { return [self KXColorWithHex:0xFEB727]; } +(instancetype)baseNewColor { return [self KXColorWithHex:0x25195C]; } +(instancetype)titleColor { return [self KXColorWithHex:0x333333]; } +(instancetype)detailTitleColor { return [self KXColorWithHex:0x999999]; } +(instancetype)KXColorWithHex:(uint32_t)hex { uint8_t r = (hex & 0xff0000) >> 16; uint8_t g = (hex & 0x00ff00) >> 8; uint8_t b = hex & 0x0000ff; return [self KXColorWithRed:r green:g blue:b]; } +(instancetype)KXColorWithHex:(uint32_t)hex alpha:(CGFloat)alpha { uint8_t r = (hex & 0xff0000) >> 16; uint8_t g = (hex & 0x00ff00) >> 8; uint8_t b = hex & 0x0000ff; return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:alpha]; } +(instancetype)KXColorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue { return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0]; } + (UIColor*)gradientHeightFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withHeight:(int)height { CGSize size = CGSizeMake(1, height); UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); NSArray* colors = [NSArray arrayWithObjects:(id)c1.CGColor, (id)c2.CGColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorspace, (__bridge CFArrayRef)colors, NULL); CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); CGGradientRelease(gradient); CGColorSpaceRelease(colorspace); UIGraphicsEndImageContext(); return [UIColor colorWithPatternImage:image]; } + (UIColor*)gradientWidthFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withWidth:(int)width { CGSize size = CGSizeMake(width, 44); UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); NSArray* colors = [NSArray arrayWithObjects:(id)c1.CGColor, (id)c2.CGColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorspace, (__bridge CFArrayRef)colors, NULL); CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(size.width, 0), 0); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); CGGradientRelease(gradient); CGColorSpaceRelease(colorspace); UIGraphicsEndImageContext(); return [UIColor colorWithPatternImage:image]; } @end