《省钱达人》与《猎豆优选》UI相同版。域名tbk

BuyProgressView.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // BuyProgressView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/9.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "BuyProgressView.h"
  9. #define KProgressBorderWidth 2.0f
  10. #define KProgressPadding 1.0f
  11. #define KProgressColor [UIColor colorWithRed:0/255.0 green:191/255.0 blue:255/255.0 alpha:1]
  12. @interface BuyProgressView()
  13. @property (nonatomic, weak) UIView *tView;
  14. @property (nonatomic, strong) UILabel *progressLabel;
  15. @property (nonatomic, strong) UILabel *countLabel;
  16. @property (nonatomic, strong) UILabel *finishLabel;
  17. @end
  18. @implementation BuyProgressView
  19. - (instancetype)initWithFrame:(CGRect)frame
  20. {
  21. if (self = [super initWithFrame:frame]) {
  22. //边框
  23. UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(104), Fitsize(14))];
  24. borderView.layer.cornerRadius = Fitsize(7);
  25. borderView.layer.masksToBounds = YES;
  26. borderView.backgroundColor = [UIColor YHColorWithHex:0xFF5000 alpha:0.4];
  27. [self addSubview:borderView];
  28. //进度
  29. UIView *tView = [[UIView alloc] init];
  30. tView.backgroundColor = [UIColor YHColorWithHex:0xFF5000];
  31. tView.layer.cornerRadius = Fitsize(7);
  32. tView.layer.masksToBounds = YES;
  33. [self addSubview:tView];
  34. self.tView = tView;
  35. self.progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 30, borderView.height)];
  36. self.progressLabel.textColor = [UIColor whiteColor];
  37. self.progressLabel.textAlignment = NSTextAlignmentRight;
  38. self.progressLabel.font = [UIFont systemFontOfSize:9];
  39. [self addSubview:self.progressLabel];
  40. self.progressLabel.right = borderView.width-10;
  41. self.countLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, borderView.width-30, borderView.height)];
  42. self.countLabel.font = [UIFont systemFontOfSize:9];
  43. self.countLabel.textColor = [UIColor whiteColor];
  44. [self addSubview:self.countLabel];
  45. self.finishLabel = [[UILabel alloc] initWithFrame:borderView.bounds];
  46. self.finishLabel.font = [UIFont systemFontOfSize:11];
  47. self.finishLabel.textColor = [UIColor whiteColor];
  48. self.finishLabel.textAlignment = NSTextAlignmentCenter;
  49. self.finishLabel.hidden = YES;
  50. self.finishLabel.text = @"已售馨";
  51. [self addSubview:self.finishLabel];
  52. }
  53. return self;
  54. }
  55. - (void)setProgress:(CGFloat)progress
  56. {
  57. _progress = progress;
  58. CGFloat maxWidth = Fitsize(104);
  59. CGFloat heigth = Fitsize(14);
  60. BOOL finish = progress>=1.0?YES:NO;
  61. if (finish) {
  62. self.finishLabel.hidden = NO;
  63. self.countLabel.hidden = YES;
  64. }else {
  65. self.progressLabel.text = [NSString stringWithFormat:@"%.f%@",progress*100,@"%"];
  66. self.finishLabel.hidden = YES;
  67. self.countLabel.hidden = NO;
  68. }
  69. _tView.frame = CGRectMake(0, 0, maxWidth * progress, heigth);
  70. }
  71. - (void)setCount:(NSString *)count {
  72. self.countLabel.text = [NSString stringWithFormat:@"已售%@件",count];
  73. }
  74. @end