CSFileDownLoadControllerView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // CSFileDownLoadControllerView.m
  3. // zhuxun
  4. //
  5. // Created by winsoft on 17/6/22.
  6. //
  7. //
  8. #import "CSFileDownLoadControllerView.h"
  9. #import "DACircularProgressView.h"
  10. @interface CSFileDownLoadControllerView()
  11. @property (nonatomic , weak) UIButton *controllerBtn;
  12. @property (nonatomic , weak) DACircularProgressView *processView;
  13. @end
  14. @implementation CSFileDownLoadControllerView
  15. - (instancetype)init
  16. {
  17. if (self = [super init]) {
  18. DACircularProgressView *processView = [[DACircularProgressView alloc] initWithFrame:CGRectMake(0, 0, self.circleSizeWH, self.circleSizeWH)];;
  19. processView.trackTintColor = [UIColor lightGrayColor];
  20. processView.progressTintColor = [UIColor blueColor];
  21. processView.innerTintColor = [UIColor whiteColor];
  22. processView.thicknessRatio = 0.1;
  23. [self addSubview:processView];
  24. self.processView = processView;
  25. UIButton *controllerBtn = [[UIButton alloc]init];
  26. [controllerBtn addTarget:self action:@selector(downUpContro) forControlEvents:UIControlEventTouchUpInside];
  27. UIImage *fav_circle_procss_image = [UIImage imageNamed:@"fav_pause_normal"];
  28. _circleSizeWH = fav_circle_procss_image.size.width;
  29. [controllerBtn setImage:fav_circle_procss_image forState:UIControlStateNormal];
  30. [controllerBtn setImage:[UIImage imageNamed:@"fav_pause_pressed"] forState:UIControlStateSelected];
  31. [self addSubview:controllerBtn];
  32. self.controllerBtn = controllerBtn;
  33. }
  34. return self;
  35. }
  36. - (void)downUpContro
  37. {
  38. if (self.downUpStatus == DownUpStatusDoing || self.downUpStatus == DownUpStatusWait) {
  39. self.downUpStatus = DownUpStatusPause;
  40. }else if (self.downUpStatus == DownUpStatusFailure || self.downUpStatus == DownUpStatusPause)
  41. {
  42. self.downUpStatus = DownUpStatusWait;
  43. }
  44. if (self.downUpStatusChangeBlock) {
  45. self.downUpStatusChangeBlock(self.downUpStatus);
  46. }
  47. }
  48. - (void)setDownUpStatus:(DownUpStatus)downUpStatus
  49. {
  50. _downUpStatus = downUpStatus;
  51. /* DownUpStatusWait = 0,//默认为排队等待.
  52. DownUpStatusDoing,
  53. DownUpStatusPause,//Pause->恢复doing时判断是否有其他进行,是则=wait.
  54. DownUpStatusSuccess,
  55. DownUpStatusFailure*/
  56. if (downUpStatus == DownUpStatusWait || downUpStatus == DownUpStatusDoing ) {
  57. [self.controllerBtn setImage:[UIImage imageNamed:@"fav_pause_normal"] forState:UIControlStateNormal];
  58. [self.controllerBtn setImage:[UIImage imageNamed:@"fav_pause_pressed"] forState:UIControlStateSelected];
  59. }else if (downUpStatus == DownUpStatusPause || downUpStatus == DownUpStatusFailure) {
  60. [self.controllerBtn setImage:[UIImage imageNamed:@"fav_download_normal"] forState:UIControlStateNormal];
  61. [self.controllerBtn setImage:[UIImage imageNamed:@"fav_download_pressed"] forState:UIControlStateSelected];
  62. }
  63. }
  64. - (void)setPercent:(CGFloat)percent
  65. {
  66. // self.processView.progress = percent;
  67. [self.processView setProgress:percent animated:NO initialDelay:0];
  68. }
  69. - (void)layoutSubviews
  70. {
  71. [super layoutSubviews];
  72. self.processView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
  73. CGFloat btnWH = self.frame.size.width * 0.9;
  74. self.controllerBtn.frame = CGRectMake((self.frame.size.width - btnWH)/2.0f, (self.frame.size.height - btnWH)/2.0f, btnWH, btnWH);
  75. }
  76. @end