FMPAImageView.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // SPMImageAsyncView.m
  3. // ImageDL
  4. //
  5. //
  6. #import "FMPAImageView.h"
  7. #pragma mark - Utils
  8. #define rad(degrees) ((degrees) / (180.0 / M_PI))
  9. #define kLineWidth 3.f
  10. NSString * const spm_identifier = @"spm.imagecache.tg";
  11. #pragma mark - SPMImageAsyncView interface
  12. @interface FMPAImageView ()
  13. @property (nonatomic, strong) CAShapeLayer *backgroundLayer;
  14. @property (nonatomic, strong) CAShapeLayer *progressLayer;
  15. @property (nonatomic, strong) UIView *progressContainer;
  16. @end
  17. #pragma mark - SPMImageAsyncView
  18. @implementation FMPAImageView
  19. - (id)initWithFrame:(CGRect)frame {
  20. return [[FMPAImageView alloc] initWithFrame:frame
  21. backgroundProgressColor:[UIColor whiteColor]];
  22. }
  23. - (id)initWithFrame:(CGRect)frame backgroundProgressColor:(UIColor *)backgroundProgresscolor
  24. {
  25. self = [super initWithFrame:frame];
  26. if (self) {
  27. self.layer.cornerRadius = CGRectGetWidth(self.bounds)/2.f;
  28. self.layer.masksToBounds = NO;
  29. self.clipsToBounds = YES;
  30. CGPoint arcCenter = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
  31. CGFloat radius = MIN(CGRectGetMidX(self.bounds)-1, CGRectGetMidY(self.bounds)-1);
  32. UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:arcCenter
  33. radius:radius
  34. startAngle:-rad(90)
  35. endAngle:rad(360-90)
  36. clockwise:YES];
  37. _backgroundLayer = [CAShapeLayer layer];
  38. _backgroundLayer.path = circlePath.CGPath;
  39. _backgroundLayer.strokeColor = [backgroundProgresscolor CGColor];
  40. _backgroundLayer.fillColor = [[UIColor clearColor] CGColor];
  41. _backgroundLayer.lineWidth = kLineWidth;
  42. }
  43. return self;
  44. }
  45. @end