JXCategoryFactory.m 983 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // JXCategoryFactory.m
  3. // JXCategoryView
  4. //
  5. // Created by jiaxin on 2018/8/17.
  6. // Copyright © 2018年 jiaxin. All rights reserved.
  7. //
  8. #import "JXCategoryFactory.h"
  9. #import "UIColor+JXAdd.h"
  10. @implementation JXCategoryFactory
  11. + (CGFloat)interpolationFrom:(CGFloat)from to:(CGFloat)to percent:(CGFloat)percent
  12. {
  13. percent = MAX(0, MIN(1, percent));
  14. return from + (to - from)*percent;
  15. }
  16. + (UIColor *)interpolationColorFrom:(UIColor *)fromColor to:(UIColor *)toColor percent:(CGFloat)percent
  17. {
  18. CGFloat red = [self interpolationFrom:fromColor.jx_red to:toColor.jx_red percent:percent];
  19. CGFloat green = [self interpolationFrom:fromColor.jx_green to:toColor.jx_green percent:percent];
  20. CGFloat blue = [self interpolationFrom:fromColor.jx_blue to:toColor.jx_blue percent:percent];
  21. CGFloat alpha = [self interpolationFrom:fromColor.jx_alpha to:toColor.jx_alpha percent:percent];
  22. return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
  23. }
  24. @end