口袋优选

KBNativeShopCarCollectionCell.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // KBNativeShopCarCollectionCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/11/6.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBNativeShopCarCollectionCell.h"
  9. @interface KBNativeShopCarCollectionCell ()
  10. @property (nonatomic, strong) UIImageView *icon;
  11. @property (nonatomic, strong) UILabel *title;
  12. @property (nonatomic, strong) YYLabel *couple_price;
  13. @property (nonatomic, strong) YYLabel *price;
  14. @property (nonatomic, strong) YYLabel *endTime;
  15. @property (nonatomic, strong) UILabel *couple_label;
  16. @end
  17. @implementation KBNativeShopCarCollectionCell
  18. - (instancetype)initWithFrame:(CGRect)frame
  19. {
  20. self = [super initWithFrame:frame];
  21. if (self) {
  22. self.contentView.backgroundColor = [UIColor whiteColor];
  23. [self initSubViews];
  24. }
  25. return self;
  26. }
  27. - (void)initSubViews {
  28. [self.contentView addSubview:self.icon];
  29. [self.contentView addSubview:self.title];
  30. [self.contentView addSubview:self.couple_price];
  31. [self.contentView addSubview:self.price];
  32. [self.contentView addSubview:self.endTime];
  33. [self.contentView addSubview:self.couple_label];
  34. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.mas_equalTo(10);
  36. make.top.mas_equalTo(5);
  37. make.width.height.mas_equalTo(78);
  38. }];
  39. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.mas_equalTo(self.icon.mas_right).mas_offset(5);
  41. make.top.mas_equalTo(self.icon.mas_top);
  42. make.right.mas_equalTo(-10);
  43. }];
  44. [self.endTime mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.mas_equalTo(self.title.mas_left);
  46. make.bottom.mas_equalTo(self.icon.mas_bottom);
  47. }];
  48. [self.couple_price mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.left.mas_equalTo(self.title.mas_left);
  50. make.top.mas_equalTo(self.title.mas_bottom).mas_offset(10);
  51. }];
  52. [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.mas_equalTo(self.couple_price.mas_right).mas_offset(20);
  54. make.bottom.mas_equalTo(self.couple_price.mas_bottom);
  55. }];
  56. [self.couple_label mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.bottom.mas_equalTo(self.endTime.mas_bottom);
  58. make.right.mas_equalTo(-10);
  59. make.width.mas_equalTo(60);
  60. make.height.mas_equalTo(23);
  61. }];
  62. }
  63. - (void)setModel:(KBChildGoodModel *)model {
  64. _model = model;
  65. [self.icon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];
  66. self.title.text = model.title;
  67. if ([model.is_coupon boolValue]) {
  68. NSString *discount_price = [NSString stringWithFormat:@"券后¥%.2f",[model.discount_price floatValue]];
  69. NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:discount_price];
  70. [disAttr yy_setFont:[UIFont systemFontOfSize:12] range:NSMakeRange(0, 3)];
  71. [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, discount_price.length-3)];
  72. disAttr.yy_color = [UIColor homeRedColor];
  73. self.couple_price.attributedText = disAttr;
  74. self.price.text = [NSString stringWithFormat:@"原价¥%@",model.price];
  75. self.couple_label.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
  76. if (model.coupon_end_time.length > 0) {
  77. self.endTime.text = [NSString stringWithFormat:@"%@ 到期",model.coupon_end_time];
  78. }
  79. }else {
  80. self.couple_price.text = [NSString stringWithFormat:@"¥%@",model.price];
  81. self.couple_price.font = [UIFont systemFontOfSize:16];
  82. }
  83. self.couple_label.hidden = ![model.is_coupon boolValue];
  84. self.endTime.hidden = ![model.is_coupon boolValue];
  85. self.price.hidden = ![model.is_coupon boolValue];
  86. }
  87. #pragma mark -----
  88. - (UIImageView *)icon {
  89. if (!_icon) {
  90. _icon = [[UIImageView alloc] init];
  91. _icon.layer.cornerRadius = 4;
  92. _icon.backgroundColor = [UIColor yhGrayColor];
  93. }
  94. return _icon;
  95. }
  96. - (UILabel *)title {
  97. if (!_title) {
  98. _title = [[UILabel alloc] init];
  99. _title.numberOfLines = 2;
  100. _title.font = [UIFont systemFontOfSize:12];
  101. }
  102. return _title;
  103. }
  104. - (YYLabel *)couple_price {
  105. if (!_couple_price) {
  106. _couple_price = [[YYLabel alloc] init];
  107. _couple_price.textColor = [UIColor homeRedColor];
  108. _couple_price.font = [UIFont systemFontOfSize:16];
  109. _couple_price.displaysAsynchronously = YES;
  110. }
  111. return _couple_price;
  112. }
  113. - (YYLabel *)price {
  114. if (!_price) {
  115. _price = [[YYLabel alloc] init];
  116. _price.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  117. _price.font = [UIFont systemFontOfSize:12];
  118. _price.displaysAsynchronously = YES;
  119. }
  120. return _price;
  121. }
  122. - (YYLabel *)endTime {
  123. if (!_endTime) {
  124. _endTime = [[YYLabel alloc] init];
  125. _endTime.font = [UIFont systemFontOfSize:11];
  126. _endTime.textColor = [UIColor YHColorWithHex:0xA2A0A0];
  127. _endTime.displaysAsynchronously = YES;
  128. }
  129. return _endTime;
  130. }
  131. - (UILabel *)couple_label {
  132. if (!_couple_label) {
  133. _couple_label = [[UILabel alloc] init];
  134. _couple_label.textColor = [UIColor whiteColor];
  135. _couple_label.font = [UIFont systemFontOfSize:13];
  136. _couple_label.textAlignment = NSTextAlignmentCenter;
  137. _couple_label.backgroundColor = [UIColor homeRedColor];
  138. }
  139. return _couple_label;
  140. }
  141. @end