口袋优选

KBMineRecomGoodsView.m 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // KBMineRecomGoodsView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/7.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBMineRecomGoodsView.h"
  9. @interface KBMineRecomGoodsView ()
  10. {
  11. UILabel *_titleLb;
  12. }
  13. @property (nonatomic, strong) UIImageView *icon;
  14. @property (nonatomic, strong) UILabel *title;
  15. @property (nonatomic, strong) YYLabel *couple_price;
  16. @property (nonatomic, strong) YYLabel *price;
  17. @property (nonatomic, strong) UIImageView *quanBg;
  18. @property (nonatomic, strong) UILabel *quanType;
  19. @property (nonatomic, strong) UILabel *quanNum;
  20. @property (nonatomic, strong) UIView *alphaView;
  21. @end
  22. @implementation KBMineRecomGoodsView
  23. - (instancetype)initWithFrame:(CGRect)frame
  24. {
  25. self = [super initWithFrame:frame];
  26. if (self) {
  27. self.layer.cornerRadius = 6;
  28. self.backgroundColor = [UIColor whiteColor];
  29. [self initSubViews];
  30. }
  31. return self;
  32. }
  33. - (void)initSubViews {
  34. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 24, 24)];
  35. imgView.image = [UIImage imageNamed:@"mine_re"];
  36. [self addSubview:imgView];
  37. UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(imgView.right+5, 0, 200, Fitsize(36))];
  38. titleLb.font = [UIFont systemFontOfSize:Fitsize(14)];
  39. titleLb.textColor = [UIColor YHColorWithHex:0x000000];
  40. _titleLb = titleLb;
  41. titleLb.centerY = imgView.centerY;
  42. [self addSubview:titleLb];
  43. UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-40-10-10, 0, 40, 40)];
  44. [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  45. rightBtn.centerY = titleLb.centerY;
  46. [rightBtn setImage:[UIImage imageNamed:@"more_acc"] forState:UIControlStateNormal];
  47. UILabel *Line = [[UILabel alloc] initWithFrame:CGRectMake(5, titleLb.bottom, self.width-10, 1)];
  48. Line.backgroundColor = [UIColor yhGrayColor];
  49. [self addSubview:Line];
  50. [self addSubview:self.icon];
  51. [self addSubview:self.title];
  52. [self addSubview:self.couple_price];
  53. [self addSubview:self.price];
  54. [self addSubview:self.quanBg];
  55. [self.quanBg addSubview:self.quanType];
  56. [self.quanBg addSubview:self.quanNum];
  57. [self addSubview:self.alphaView];
  58. [self addSubview:rightBtn];
  59. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.left.mas_equalTo(5);
  61. make.top.mas_equalTo(Line.mas_bottom).mas_offset(12);
  62. make.width.height.mas_equalTo(70);
  63. }];
  64. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.mas_equalTo(self.icon.mas_right).mas_offset(10);
  66. make.top.mas_equalTo(self.icon.mas_top);
  67. make.right.mas_equalTo(-10);
  68. }];
  69. [self.couple_price mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(self.title);
  71. make.bottom.mas_equalTo(self.icon.mas_bottom).mas_offset(-3);
  72. }];
  73. [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(self.couple_price.mas_right).mas_offset(15);
  75. make.centerY.mas_equalTo(self.couple_price);
  76. }];
  77. [self.quanBg mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.width.mas_equalTo(67);
  79. make.height.mas_equalTo(22);
  80. make.bottom.mas_equalTo(self.icon.mas_bottom).mas_offset(-5);
  81. make.right.mas_equalTo(-10);
  82. }];
  83. [self.quanType mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.top.bottom.left.mas_equalTo(0);
  85. make.width.mas_equalTo(24);
  86. }];
  87. [self.quanNum mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.mas_equalTo(27);
  89. make.top.bottom.mas_equalTo(0);
  90. make.right.mas_equalTo(-3);
  91. }];
  92. [self.alphaView mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.edges.mas_equalTo(UIEdgeInsetsZero);
  94. }];
  95. }
  96. - (void)setModel:(KBChildGoodModel *)model {
  97. _model = model;
  98. _titleLb.text = model.tag_disc;
  99. [self.icon sd_setImageWithURL:[NSURL URLWithString:model.img]];
  100. self.title.text = model.title;
  101. NSString *discount_price = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]];
  102. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:discount_price];
  103. [disAttr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 3)];
  104. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, discount_price.length-3)];
  105. disAttr.yy_color = [UIColor homeRedColor];
  106. self.couple_price.attributedText = disAttr;
  107. NSString *price = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  108. NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
  109. attrStr.yy_font = [UIFont systemFontOfSize:11];
  110. attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
  111. YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@1 color:[UIColor YHColorWithHex:0x999999]];
  112. [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(0, price.length)];
  113. self.price.attributedText = attrStr;
  114. self.quanNum.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  115. self.quanBg.hidden = ![model.is_coupon boolValue];
  116. }
  117. - (void)tapAlphaView {
  118. if (self.tapBlock) {
  119. self.tapBlock(_model);
  120. }
  121. }
  122. - (void)rightBtnClick {
  123. if (self.rightClick) {
  124. self.rightClick();
  125. }
  126. }
  127. - (UIImageView *)icon {
  128. if (!_icon) {
  129. _icon = [[UIImageView alloc] init];
  130. _icon.layer.cornerRadius = 4;
  131. _icon.backgroundColor = [UIColor yhGrayColor];
  132. }
  133. return _icon;
  134. }
  135. - (UILabel *)title {
  136. if (!_title) {
  137. _title = [[UILabel alloc] init];
  138. _title.numberOfLines = 2;
  139. _title.font = [UIFont systemFontOfSize:14];
  140. }
  141. return _title;
  142. }
  143. - (YYLabel *)couple_price {
  144. if (!_couple_price) {
  145. _couple_price = [[YYLabel alloc] init];
  146. _couple_price.textColor = [UIColor homeRedColor];
  147. _couple_price.font = [UIFont systemFontOfSize:16];
  148. _couple_price.displaysAsynchronously = YES;
  149. }
  150. return _couple_price;
  151. }
  152. - (YYLabel *)price {
  153. if (!_price) {
  154. _price = [[YYLabel alloc] init];
  155. _price.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  156. _price.font = [UIFont systemFontOfSize:12];
  157. }
  158. return _price;
  159. }
  160. - (UIImageView *)quanBg {
  161. if (!_quanBg) {
  162. _quanBg = [[UIImageView alloc] init];
  163. _quanBg.image = [UIImage imageNamed:@"quan_bg_3"];
  164. }
  165. return _quanBg;
  166. }
  167. - (UILabel *)quanType {
  168. if (!_quanType) {
  169. _quanType = [[UILabel alloc] init];
  170. _quanType.text = @"券";
  171. _quanType.textColor = [UIColor whiteColor];
  172. _quanType.font = [UIFont systemFontOfSize:13];
  173. _quanType.textAlignment = NSTextAlignmentCenter;
  174. }
  175. return _quanType;
  176. }
  177. - (UILabel *)quanNum {
  178. if (!_quanNum) {
  179. _quanNum = [[UILabel alloc] init];
  180. _quanNum.textColor = [UIColor whiteColor];
  181. _quanNum.font = [UIFont systemFontOfSize:13];
  182. _quanNum.textAlignment = NSTextAlignmentCenter;
  183. _quanNum.adjustsFontSizeToFitWidth = YES;
  184. }
  185. return _quanNum;
  186. }
  187. - (UIView *)alphaView {
  188. if (!_alphaView) {
  189. _alphaView = [[UIView alloc] init];
  190. _alphaView.backgroundColor = [UIColor clearColor];
  191. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAlphaView)];
  192. [_alphaView addGestureRecognizer:tap];
  193. }
  194. return _alphaView;
  195. }
  196. @end