TZProgressView.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // TZProgressView.m
  3. // TZImagePickerController
  4. //
  5. // Created by ttouch on 2016/12/6.
  6. // Copyright © 2016年 谭真. All rights reserved.
  7. //
  8. #import "TZProgressView.h"
  9. @interface TZProgressView ()
  10. @property (nonatomic, strong) CAShapeLayer *progressLayer;
  11. @end
  12. @implementation TZProgressView
  13. - (instancetype)init {
  14. self = [super init];
  15. if (self) {
  16. self.backgroundColor = [UIColor clearColor];
  17. _progressLayer = [CAShapeLayer layer];
  18. _progressLayer.fillColor = [[UIColor clearColor] CGColor];
  19. _progressLayer.strokeColor = [[UIColor whiteColor] CGColor];
  20. _progressLayer.opacity = 1;
  21. _progressLayer.lineCap = kCALineCapRound;
  22. _progressLayer.lineWidth = 5;
  23. [_progressLayer setShadowColor:[UIColor blackColor].CGColor];
  24. [_progressLayer setShadowOffset:CGSizeMake(1, 1)];
  25. [_progressLayer setShadowOpacity:0.5];
  26. [_progressLayer setShadowRadius:2];
  27. }
  28. return self;
  29. }
  30. - (void)drawRect:(CGRect)rect {
  31. CGPoint center = CGPointMake(rect.size.width / 2, rect.size.height / 2);
  32. CGFloat radius = rect.size.width / 2;
  33. CGFloat startA = - M_PI_2;
  34. CGFloat endA = - M_PI_2 + M_PI * 2 * _progress;
  35. _progressLayer.frame = self.bounds;
  36. UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
  37. _progressLayer.path =[path CGPath];
  38. [_progressLayer removeFromSuperlayer];
  39. [self.layer addSublayer:_progressLayer];
  40. }
  41. - (void)setProgress:(double)progress {
  42. _progress = progress;
  43. [self setNeedsDisplay];
  44. }
  45. @end