YQGradientProgressView.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // YQGradientProgressView.m
  3. // shehui
  4. //
  5. // Created by pajia on 16/7/6.
  6. // Copyright © 2016年 happyfirst. All rights reserved.
  7. //
  8. #import "YQGradientProgressView.h"
  9. #import "UIView+AZGradient.h"
  10. @implementation YQGradientProgressModel
  11. @end
  12. @interface YQGradientProgressView()
  13. {
  14. UIView *_pView;
  15. // CAGradientLayer *_gradientLayer;
  16. }
  17. @end
  18. @implementation YQGradientProgressView
  19. - (id)init{
  20. if (self = [super init]) {
  21. [self setupView];
  22. }
  23. return self;
  24. }
  25. - (void)setupView{
  26. self.backgroundColor = [UIColor clearColor];
  27. kViewRadius(self, 2);
  28. _pView = [[UIView alloc] init];
  29. kViewRadius(_pView, 2);
  30. [self addSubview:_pView];
  31. // _gradientLayer = [CAGradientLayer layer];
  32. // [_pView.layer addSublayer:_gradientLayer];
  33. }
  34. - (void)setProgress:(float)progress{
  35. _progress = progress;
  36. if (_progress > 1.0) {
  37. _progress = 1.0;
  38. }
  39. if (_progress < 0) {
  40. _progress = 0;
  41. }
  42. float width = progress*self.frame.size.width;
  43. _pView.frame = CGRectMake(0, 0, width, 4);
  44. // _gradientLayer.frame = _pView.frame;
  45. [self reloadColor];
  46. }
  47. - (void)reloadColor{
  48. self.backgroundColor = [UIColor colorWithHexString:self.colorMoodel.backGroundColor alpha:0.1];
  49. // UIColor *color1,*color2;
  50. //if (_progress <= 0.5) {
  51. // color1 = [UIColor colorWithHexString:@"4ad7ff" alpha:1];
  52. //color2 = [UIColor colorWithHexString:@"1bc1ff" alpha:1];
  53. //}else{
  54. // color1 = [UIColor colorWithHexString:@"ffd33a" alpha:1];
  55. // color2 = [UIColor colorWithHexString:@"ffa126" alpha:1];
  56. //}
  57. //set gradient colors
  58. // color1 = [UIColor colorWithHexString:self.colorMoodel.startColor alpha:1];
  59. // color2 = [UIColor colorWithHexString:self.colorMoodel.endColor alpha:1];
  60. // _gradientLayer.colors = @[(__bridge id)color1.CGColor, (__bridge id)color2.CGColor];
  61. // //set gradient start and end points
  62. // _gradientLayer.startPoint = CGPointMake(0, 0.5);
  63. // _gradientLayer.endPoint = CGPointMake(1, 0.5);
  64. [_pView az_setGradientBackgroundWithColors:@[[UIColor colorWithHexString:self.colorMoodel.startColor alpha:1],[UIColor colorWithHexString:self.colorMoodel.endColor alpha:1]] locations:nil startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5)];
  65. }
  66. /*
  67. // Only override drawRect: if you perform custom drawing.
  68. // An empty implementation adversely affects performance during animation.
  69. - (void)drawRect:(CGRect)rect {
  70. // Drawing code
  71. }
  72. */
  73. @end