123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // UIColor+KDPColor.m
- // KuDianProject
- //
- // Created by 学丽 on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "UIColor+KDPColor.h"
- @implementation UIColor (KDPColor)
- + (UIColor*)gradientOneColor:(UIColor*)oneColor toColor:(UIColor*)twoColor Width:(int)width
- {
- CGSize size = CGSizeMake(width, 44);
- UIGraphicsBeginImageContextWithOptions(size, NO, 0);
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
-
- NSArray* colors = [NSArray arrayWithObjects:(id)oneColor.CGColor, (id)twoColor.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];
- }
- +(instancetype)colorWithHex:(uint32_t)hex
- {
- uint8_t r = (hex & 0xff0000) >> 16;
- uint8_t g = (hex & 0x00ff00) >> 8;
- uint8_t b = hex & 0x0000ff;
-
- return [self colorWithRed:r green:g blue:b];
- }
- +(instancetype)colorWithRed:(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];
- }
- + (instancetype)baseColor{
- return [self colorWithHex:0xFF235F];
- }
- @end
|