No Description

UIColor+KXHex.m 3.2KB

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