dkahgld

UIColor+ZBColor.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // UIColor+ZBColor.m
  3. // ZBProject
  4. //
  5. // Created by 学丽 on 2019/3/26.
  6. // Copyright © 2019 ZB. All rights reserved.
  7. //
  8. #import "UIColor+ZBColor.h"
  9. @implementation UIColor (ZBColor)
  10. + (UIColor*)gradientHeightFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withHeight:(int)height
  11. {
  12. CGSize size = CGSizeMake(1, height);
  13. UIGraphicsBeginImageContextWithOptions(size, NO, 0);
  14. CGContextRef context = UIGraphicsGetCurrentContext();
  15. CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
  16. NSArray* colors = [NSArray arrayWithObjects:(id)c1.CGColor, (id)c2.CGColor, nil];
  17. CGGradientRef gradient = CGGradientCreateWithColors(colorspace, (__bridge CFArrayRef)colors, NULL);
  18. CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0);
  19. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  20. CGGradientRelease(gradient);
  21. CGColorSpaceRelease(colorspace);
  22. UIGraphicsEndImageContext();
  23. return [UIColor colorWithPatternImage:image];
  24. }
  25. + (UIColor*)gradientWidthFromColor:(UIColor*)c1 toColor:(UIColor*)c2 withWidth:(int)width
  26. {
  27. CGSize size = CGSizeMake(width, 44);
  28. UIGraphicsBeginImageContextWithOptions(size, NO, 0);
  29. CGContextRef context = UIGraphicsGetCurrentContext();
  30. CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
  31. NSArray* colors = [NSArray arrayWithObjects:(id)c1.CGColor, (id)c2.CGColor, nil];
  32. CGGradientRef gradient = CGGradientCreateWithColors(colorspace, (__bridge CFArrayRef)colors, NULL);
  33. CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(size.width, 0), 0);
  34. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  35. CGGradientRelease(gradient);
  36. CGColorSpaceRelease(colorspace);
  37. UIGraphicsEndImageContext();
  38. return [UIColor colorWithPatternImage:image];
  39. }
  40. +(instancetype)changeColor
  41. {
  42. return [self gradientWidthFromColor:[UIColor colorWithRGB:0xFC7123] toColor:[UIColor colorWithRGB:0xFA2C36] withWidth:SCREEN_WIDTH];
  43. }
  44. +(instancetype)backgroudColor
  45. {
  46. return [self YHColorWithHex:0xf2f2f2];
  47. }
  48. +(instancetype)lineColor
  49. {
  50. return [self YHColorWithHex:0xF4F4F4];
  51. }
  52. + (instancetype)baseColor
  53. {
  54. return [self YHColorWithHex:0xFF7D00];
  55. }
  56. + (instancetype)yhGrayColor {
  57. return [self YHColorWithHex:0xf5f4f4];
  58. }
  59. + (instancetype)homeRedColor {
  60. return [self YHColorWithHex:0xFA2C36];
  61. }
  62. + (instancetype)YHColorWithHex:(uint32_t)hex
  63. {
  64. uint8_t r = (hex & 0xff0000) >> 16;
  65. uint8_t g = (hex & 0x00ff00) >> 8;
  66. uint8_t b = hex & 0x0000ff;
  67. return [self YHColorWithRed:r green:g blue:b];
  68. }
  69. + (instancetype)YHColorWithHex:(uint32_t)hex alpha:(CGFloat)alpha
  70. {
  71. uint8_t r = (hex & 0xff0000) >> 16;
  72. uint8_t g = (hex & 0x00ff00) >> 8;
  73. uint8_t b = hex & 0x0000ff;
  74. return [UIColor colorWithRed:r / 255.0 green:g / 255.0 blue:b / 255.0 alpha:alpha];
  75. }
  76. + (instancetype)YHColorWithRed:(uint8_t)red green:(uint8_t)green blue:(uint8_t)blue
  77. {
  78. return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0];
  79. }
  80. +(instancetype)fontNineColor
  81. {
  82. return [self YHColorWithHex:0x999999];
  83. }
  84. +(instancetype)fontsixColor
  85. {
  86. return [self YHColorWithHex:0x666666];
  87. }
  88. +(instancetype)fontColor
  89. {
  90. return [self YHColorWithHex:0x333333];
  91. }
  92. @end