口袋优选

KBBuyLimitGoodView.m 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // KBBuyLimitGoodView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/9.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBBuyLimitGoodView.h"
  9. #import "BuyProgressView.h"
  10. @interface KBBuyLimitGoodView ()
  11. @property (nonatomic, strong) UIImageView *iconView;
  12. @property (nonatomic, strong) UILabel *titleLabel;
  13. @property (nonatomic, strong) BuyProgressView *progressView;
  14. @property (nonatomic, strong) UILabel *priceLabel;
  15. @property (nonatomic, strong) UILabel *disPriceLabel;
  16. @property (nonatomic, strong) UILabel *coupleLabel;
  17. @end
  18. @implementation KBBuyLimitGoodView
  19. - (instancetype)initWithFrame:(CGRect)frame {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. [self initSubViews];
  23. }
  24. return self;
  25. }
  26. - (void)initSubViews {
  27. [self addSubview:self.iconView];
  28. [self addSubview:self.titleLabel];
  29. [self addSubview:self.priceLabel];
  30. [self addSubview:self.disPriceLabel];
  31. [self addSubview:self.buyButton];
  32. [self addSubview:self.progressView];
  33. [self addSubview:self.coupleLabel];
  34. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.top.mas_equalTo(0);
  36. make.width.height.mas_equalTo(94);
  37. }];
  38. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.top.mas_equalTo(5);
  40. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(5);
  41. }];
  42. [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.mas_equalTo(self.titleLabel.mas_left);
  44. make.centerY.mas_equalTo(self.iconView.mas_centerY);
  45. make.width.mas_equalTo(Fitsize(104));
  46. make.height.mas_equalTo(Fitsize(14));
  47. }];
  48. [self.disPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(self.titleLabel.mas_left);
  50. make.bottom.mas_equalTo(self.iconView.mas_bottom).mas_offset(-3);
  51. }];
  52. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(self.disPriceLabel.mas_right).mas_offset(7);
  54. make.centerY.mas_equalTo(self.disPriceLabel.mas_centerY);
  55. }];
  56. [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.right.mas_equalTo(0);
  58. make.bottom.mas_equalTo(self.priceLabel.mas_bottom);
  59. make.width.mas_equalTo(Fitsize(77));
  60. make.height.mas_equalTo(Fitsize(22));
  61. }];
  62. [self.coupleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.right.mas_equalTo(-10);
  64. make.centerY.mas_equalTo(self.mas_centerY);
  65. make.height.mas_equalTo(Fitsize(16));
  66. make.width.mas_equalTo(Fitsize(50));
  67. }];
  68. }
  69. - (void)setModel:(KBBuyLimitGoodModel *)model {
  70. _model = model;
  71. self.titleLabel.text = model.title;
  72. // [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img];
  73. [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  74. [self.progressView setProgress:model.sale_rate.floatValue/100];
  75. [self.progressView setCount:model.sale_num];
  76. self.disPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  77. NSString *price=[NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  78. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:price];
  79. [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, price.length)];
  80. [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor YHColorWithHex:0x999999] range:NSMakeRange(0, price.length)];
  81. self.priceLabel.attributedText = attri;
  82. // if (model.commission_price.length > 0) {
  83. // [self.buyButton setTitle:[NSString stringWithFormat:@"抢赚¥%.2f",[model.commission_price floatValue]] forState:UIControlStateNormal];
  84. // }else {
  85. // [self.buyButton setTitle:@"抢购" forState:UIControlStateNormal];
  86. // }
  87. self.coupleLabel.hidden = ![model.is_coupon boolValue];
  88. self.coupleLabel.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
  89. }
  90. - (UIImageView *)iconView {
  91. if (!_iconView) {
  92. _iconView = [[UIImageView alloc] init];
  93. _iconView.clipsToBounds = YES;
  94. _iconView.layer.cornerRadius = 4;
  95. _iconView.backgroundColor = [UIColor yhGrayColor];
  96. }
  97. return _iconView;
  98. }
  99. - (UILabel *)titleLabel {
  100. if (!_titleLabel) {
  101. _titleLabel = [[UILabel alloc] init];
  102. _titleLabel.numberOfLines = 2;
  103. _titleLabel.font = [UIFont systemFontOfSize:Fitsize(14)];
  104. _titleLabel.textColor = [UIColor YHColorWithHex:0x2D2D2D];
  105. _titleLabel.text = @"标题加载中...";
  106. }
  107. return _titleLabel;
  108. }
  109. - (UILabel *)priceLabel {
  110. if (!_priceLabel) {
  111. _priceLabel = [[UILabel alloc] init];
  112. _priceLabel.font = [UIFont systemFontOfSize:Fitsize(12)];
  113. _priceLabel.textColor = [UIColor YHColorWithHex:0xB6B6B6];
  114. _priceLabel.text = @"¥--";
  115. }
  116. return _priceLabel;
  117. }
  118. - (UILabel *)disPriceLabel {
  119. if (!_disPriceLabel) {
  120. _disPriceLabel = [[UILabel alloc] init];
  121. _disPriceLabel.textColor = [UIColor homeRedColor];
  122. _disPriceLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
  123. _disPriceLabel.text = @"¥--";
  124. }
  125. return _disPriceLabel;
  126. }
  127. - (UIButton *)buyButton {
  128. if (!_buyButton) {
  129. _buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
  130. _buyButton.backgroundColor = [UIColor homeRedColor];
  131. _buyButton.titleLabel.font = [UIFont systemFontOfSize:13];
  132. _buyButton.layer.cornerRadius = Fitsize(10);
  133. _buyButton.titleLabel.textColor = [UIColor whiteColor];
  134. [_buyButton setTitle:@"抢购" forState:UIControlStateNormal];
  135. _buyButton.userInteractionEnabled = NO;
  136. }
  137. return _buyButton;
  138. }
  139. - (BuyProgressView *)progressView {
  140. if (!_progressView) {
  141. _progressView = [BuyProgressView new];
  142. }
  143. return _progressView;
  144. }
  145. - (UILabel *)coupleLabel {
  146. if (!_coupleLabel) {
  147. _coupleLabel = [[UILabel alloc] init];
  148. _coupleLabel.textColor = [UIColor homeRedColor];
  149. _coupleLabel.font = [UIFont systemFontOfSize:Fitsize(12)];
  150. _coupleLabel.textAlignment = NSTextAlignmentCenter;
  151. _coupleLabel.layer.cornerRadius = Fitsize(4);
  152. _coupleLabel.layer.borderWidth = 1;
  153. _coupleLabel.layer.borderColor = [UIColor homeRedColor].CGColor;
  154. _coupleLabel.hidden = YES;
  155. }
  156. return _coupleLabel;
  157. }
  158. @end