ProgressBarView.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // ProgressBarView.m
  3. // jiaPei
  4. //
  5. // Created by apple on 2017/5/12.
  6. // Copyright © 2017年 JCZ. All rights reserved.
  7. //
  8. #import "ProgressBarView.h"
  9. @implementation ProgressBarView
  10. -(instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self) {
  13. CGFloat x,y,w,h;
  14. x = 10;
  15. y = 0;
  16. w = 90;
  17. h = 25;
  18. UILabel *label = [[UILabel alloc] setxywh];
  19. [label setText:@"" Font:FontTitle TextColor:kTitleColor];
  20. [self addSubview:label];
  21. titleLabel = label;
  22. x += w;
  23. y += 5;
  24. w = kSize.width - x - 60;
  25. h = 15;
  26. label = [[UILabel alloc] setxywh];
  27. label.backgroundColor = RQlineColor;
  28. label.layer.masksToBounds = YES;
  29. label.layer.cornerRadius = 7;
  30. [self addSubview:label];
  31. allLabel = label;
  32. label = [[UILabel alloc] setxywh];
  33. label.backgroundColor = RQ_MAIN_COLOR;
  34. label.layer.masksToBounds = YES;
  35. label.layer.cornerRadius = 7;
  36. [self addSubview:label];
  37. label.hidden = YES;
  38. nowLabel = label;
  39. x += w;
  40. y -= 5;
  41. w = 50;
  42. h = 25;
  43. label = [[UILabel alloc] setxywh];
  44. [label setText:@"" Font:FontTitle TextColor:kTitleColor];
  45. [self addSubview:label];
  46. progressLabel = label;
  47. x = 100;
  48. y += h;
  49. w = kSize.width - x;
  50. h = 25;
  51. label = [[UILabel alloc] setxywh];
  52. [label setText:@"" Font:FontTitle TextColor:kTitleColor];
  53. [self addSubview:label];
  54. contentLabel = label;
  55. }
  56. return self;
  57. }
  58. -(void)setTitleString:(NSString *)titleString {
  59. _titleString = titleString;
  60. titleLabel.text = titleString;
  61. }
  62. - (void)setFinishCount:(NSInteger)finishCount {
  63. _finishCount = finishCount;
  64. [contentLabel removeFromSuperview];
  65. //防止除0
  66. if (_allCount == 0) {
  67. _allCount = 50;
  68. }
  69. progressLabel.text = [NSString stringWithFormat:@"%d/%d",(int)finishCount,(int)_allCount];
  70. nowLabel.hidden = NO;
  71. nowLabel.width = allLabel.width * finishCount / _allCount;
  72. }
  73. - (void)setFinishTime:(NSInteger)finishTime {
  74. _finishTime = finishTime;
  75. //防止除0
  76. if (_allNeedTime == 0) {
  77. _allNeedTime = 240;
  78. }
  79. NSInteger allHour = _allNeedTime/(_RATIONKS? : 60);
  80. NSInteger allMin = _allNeedTime%(_RATIONKS? : 60);
  81. NSString *allTimeString = [NSString stringWithFormat:@"%d%@%d分钟",(int)allHour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),(int)allMin];
  82. if (allHour == 0) {
  83. allTimeString = [NSString stringWithFormat:@"%d分钟",(int)allMin];
  84. }
  85. if (finishTime > 0) {
  86. NSInteger hour = finishTime/(_RATIONKS? : 60);
  87. NSInteger min = finishTime%(_RATIONKS? : 60);
  88. NSString *timeString = [NSString stringWithFormat:@"%d%@%d分钟",(int)hour,(RQStringIsNotEmpty(_RATIONKSMC)? _RATIONKSMC : @"小时"),(int)min];
  89. if (hour == 0) {
  90. timeString = [NSString stringWithFormat:@"%d分钟",(int)min];
  91. }
  92. //在这个地方给进度条赋值
  93. CGFloat progressValue = finishTime*1.0/_allNeedTime*100;
  94. progressLabel.text = [NSString stringWithFormat:@"%.0f%%",progressValue];
  95. nowLabel.hidden = NO;
  96. nowLabel.width = allLabel.width * progressValue/100.0;
  97. contentLabel.text = [NSString stringWithFormat:@"已完成%@,共需%@",timeString,allTimeString];
  98. }else {
  99. nowLabel.hidden = YES;
  100. progressLabel.text = @"0%";
  101. contentLabel.text = [NSString stringWithFormat:@"已完成0分钟,共需%@",allTimeString];
  102. }
  103. }
  104. @end