123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // UIColor+ZBColor.m
- // ZBProject
- //
- // Created by 学丽 on 2019/3/26.
- // Copyright © 2019 ZB. All rights reserved.
- //
- #import "UIColor+ZBColor.h"
- @implementation UIColor (ZBColor)
- + (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];
- }
- +(instancetype)changeColor
- {
- return [self gradientWidthFromColor:[UIColor colorWithRGB:0xFC7123] toColor:[UIColor colorWithRGB:0xFA2C36] withWidth:SCREEN_WIDTH];
- }
- +(instancetype)backgroudColor
- {
- return [self YHColorWithHex:0xf2f2f2];
- }
- +(instancetype)lineColor
- {
- return [self YHColorWithHex:0xF4F4F4];
- }
- + (instancetype)baseColor
- {
- return [self YHColorWithHex:0xFF7D00];
- }
- + (instancetype)yhGrayColor {
- return [self YHColorWithHex:0xf5f4f4];
- }
- + (instancetype)homeRedColor {
- return [self YHColorWithHex:0xFA2C36];
- }
- + (instancetype)YHColorWithHex:(uint32_t)hex
- {
- uint8_t r = (hex & 0xff0000) >> 16;
- uint8_t g = (hex & 0x00ff00) >> 8;
- uint8_t b = hex & 0x0000ff;
-
- return [self YHColorWithRed:r green:g blue:b];
- }
- + (instancetype)YHColorWithHex:(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)YHColorWithRed:(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)fontNineColor
- {
- return [self YHColorWithHex:0x999999];
- }
- +(instancetype)fontsixColor
- {
- return [self YHColorWithHex:0x666666];
- }
- +(instancetype)fontColor
- {
- return [self YHColorWithHex:0x333333];
- }
- @end
|