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

DRCollectionTicketCell.m 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // DRCollectionTicketCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRCollectionTicketCell.h"
  9. @interface DRCollectionTicketCell ()
  10. @property (nonatomic, strong) UIImageView *iconView;
  11. @property (nonatomic, strong) UILabel *titleLabel;
  12. @property (nonatomic, strong) UILabel *endDateLabel;
  13. @property (nonatomic, strong) UILabel *priceLabel;
  14. @property (nonatomic, strong) UILabel *disPriceLabel;
  15. @property (nonatomic, strong) UIImageView *ticketImg;
  16. @property (nonatomic, strong) UILabel *ticketLabel;
  17. @property (nonatomic, strong) UILabel *outTimeLabel;
  18. @property (nonatomic, strong) UIButton *sameButton;
  19. @end
  20. @implementation DRCollectionTicketCell
  21. + (instancetype)cellWithTableView:(UITableView *)tableView {
  22. static NSString *cellID = nil;
  23. cellID = NSStringFromClass([self class]);
  24. DRCollectionTicketCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  25. if (!cell) {
  26. cell = [[DRCollectionTicketCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  27. }
  28. return cell;
  29. }
  30. - (void)awakeFromNib {
  31. [super awakeFromNib];
  32. // Initialization code
  33. }
  34. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  35. [super setSelected:selected animated:animated];
  36. // Configure the view for the selected state
  37. }
  38. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  39. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  40. if (self) {
  41. [self initSubView];
  42. }
  43. return self;
  44. }
  45. - (void)initSubView {
  46. [self.contentView addSubview:self.iconView];
  47. [self.contentView addSubview:self.titleLabel];
  48. [self.contentView addSubview:self.endDateLabel];
  49. [self.contentView addSubview:self.priceLabel];
  50. [self.contentView addSubview:self.disPriceLabel];
  51. [self.contentView addSubview:self.ticketImg];
  52. [self.contentView addSubview:self.sameButton];
  53. [self.ticketImg addSubview:self.ticketLabel];
  54. [self.iconView addSubview:self.outTimeLabel];
  55. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(15);
  57. make.width.height.mas_equalTo(80);
  58. make.top.mas_equalTo(10);
  59. }];
  60. [self.outTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.right.top.bottom.mas_equalTo(0);
  62. }];
  63. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.top.mas_equalTo(10);
  65. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
  66. make.right.mas_equalTo(-10);
  67. }];
  68. [self.endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(self.titleLabel.mas_left);
  70. make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(8);
  71. make.right.mas_equalTo(-10);
  72. }];
  73. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(self.titleLabel.mas_left);
  75. make.bottom.mas_equalTo(-10);
  76. }];
  77. [self.disPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.left.mas_equalTo(self.priceLabel.mas_right).mas_offset(5);
  79. make.centerY.mas_equalTo(self.priceLabel.mas_centerY);
  80. }];
  81. [self.ticketImg mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.right.mas_equalTo(-10);
  83. make.bottom.mas_equalTo(self.iconView.mas_bottom);
  84. make.width.mas_equalTo(60);
  85. make.height.mas_equalTo(20);
  86. }];
  87. [self.ticketLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.right.top.bottom.mas_equalTo(0);
  89. }];
  90. [self.sameButton mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.mas_equalTo(-10);
  92. make.bottom.mas_equalTo(self.iconView.mas_bottom);
  93. make.width.mas_equalTo(60);
  94. make.height.mas_equalTo(23);
  95. }];
  96. }
  97. - (void)setModel:(DRCollectionModel *)model {
  98. _model = model;
  99. [_iconView sd_setImageWithURL:[NSURL URLWithString:model.img]];
  100. self.titleLabel.text = model.title;
  101. self.outTimeLabel.hidden = ![model.is_outdate boolValue];
  102. self.ticketImg.hidden = [model.is_outdate boolValue];
  103. self.sameButton.hidden = ![model.is_outdate boolValue];
  104. self.endDateLabel.text = [NSString stringWithFormat:@"到期时间:%@",model.end_time];
  105. self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  106. NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  107. NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11],
  108. NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999],
  109. NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999],
  110. NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}];
  111. self.disPriceLabel.attributedText = attr;
  112. self.ticketLabel.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
  113. }
  114. - (void)setHistoryModel:(DRHistoryModel *)historyModel {
  115. _historyModel = historyModel;
  116. [_iconView sd_setImageWithURL:[NSURL URLWithString:historyModel.img]];
  117. self.titleLabel.text = historyModel.title;
  118. BOOL isOutTime = [PublicFunction isOuttimeDate:historyModel.end_time];
  119. self.outTimeLabel.hidden = !isOutTime;
  120. self.ticketImg.hidden = isOutTime;
  121. self.sameButton.hidden = !isOutTime;
  122. self.endDateLabel.text = [NSString stringWithFormat:@"到期时间:%@",historyModel.end_time];
  123. self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[historyModel.discount_price floatValue]];
  124. NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[historyModel.price floatValue]];
  125. NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11],
  126. NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999],
  127. NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999],
  128. NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}];
  129. self.disPriceLabel.attributedText = attr;
  130. self.ticketLabel.text = [NSString stringWithFormat:@"%@元券",historyModel.coupon_price];
  131. }
  132. /**
  133. 找相似
  134. */
  135. - (void)findSamiliar {
  136. if (self.similarClick) {
  137. self.similarClick();
  138. }
  139. }
  140. #pragma mark ------------------
  141. - (UIImageView *)iconView {
  142. if (!_iconView) {
  143. _iconView = [[UIImageView alloc] init];
  144. _iconView.backgroundColor = [UIColor yhGrayColor];
  145. }
  146. return _iconView;
  147. }
  148. - (UILabel *)titleLabel {
  149. if (!_titleLabel) {
  150. _titleLabel = [[UILabel alloc] init];
  151. _titleLabel.textColor = [UIColor YHColorWithHex:0x444444];
  152. _titleLabel.font = [UIFont systemFontOfSize:14];
  153. _titleLabel.numberOfLines = 2;
  154. }
  155. return _titleLabel;
  156. }
  157. - (UILabel *)endDateLabel {
  158. if (!_endDateLabel) {
  159. _endDateLabel = [[UILabel alloc] init];
  160. _endDateLabel.textColor = [UIColor YHColorWithHex:0x999999];
  161. _endDateLabel.font = [UIFont systemFontOfSize:11];
  162. }
  163. return _endDateLabel;
  164. }
  165. - (UILabel *)priceLabel {
  166. if (!_priceLabel) {
  167. _priceLabel = [[UILabel alloc] init];
  168. _priceLabel.font = [UIFont systemFontOfSize:15];
  169. _priceLabel.textColor = [UIColor homeRedColor];
  170. }
  171. return _priceLabel;
  172. }
  173. - (UILabel *)disPriceLabel {
  174. if (!_disPriceLabel) {
  175. _disPriceLabel = [[UILabel alloc] init];
  176. _disPriceLabel.font = [UIFont systemFontOfSize:11];
  177. _disPriceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  178. }
  179. return _disPriceLabel;
  180. }
  181. - (UIImageView *)ticketImg {
  182. if (!_ticketImg) {
  183. _ticketImg = [[UIImageView alloc] init];
  184. _ticketImg.image = [UIImage imageNamed:@"sale"];
  185. }
  186. return _ticketImg;
  187. }
  188. - (UILabel *)ticketLabel {
  189. if (!_ticketLabel) {
  190. _ticketLabel = [[UILabel alloc] init];
  191. _ticketLabel.textColor = [UIColor whiteColor];
  192. _ticketLabel.font = [UIFont systemFontOfSize:14];
  193. _ticketLabel.textAlignment = NSTextAlignmentCenter;
  194. _ticketLabel.backgroundColor = [UIColor clearColor];
  195. }
  196. return _ticketLabel;
  197. }
  198. - (UILabel *)outTimeLabel {
  199. if (!_outTimeLabel) {
  200. _outTimeLabel = [[UILabel alloc] init];
  201. _outTimeLabel.text = @"已过期";
  202. _outTimeLabel.textAlignment = NSTextAlignmentCenter;
  203. _outTimeLabel.textColor = [UIColor whiteColor];
  204. _outTimeLabel.font = [UIFont systemFontOfSize:12];
  205. _outTimeLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  206. }
  207. return _outTimeLabel;
  208. }
  209. - (UIButton *)sameButton {
  210. if (!_sameButton) {
  211. _sameButton = [UIButton buttonWithType:UIButtonTypeCustom];
  212. _sameButton.backgroundColor = [UIColor YHColorWithHex:0xFFAA31];
  213. [_sameButton setTitle:@"找相似" forState:UIControlStateNormal];
  214. _sameButton.titleLabel.textColor = [UIColor whiteColor];
  215. _sameButton.titleLabel.font = [UIFont systemFontOfSize:13];
  216. _sameButton.userInteractionEnabled = YES;
  217. [_sameButton addTarget:self action:@selector(findSamiliar) forControlEvents:UIControlEventTouchUpInside];
  218. }
  219. return _sameButton;
  220. }
  221. @end