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

DRMyTicketCell.m 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // DRMyTicketCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/25.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRMyTicketCell.h"
  9. @interface DRMyTicketCell ()
  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 *endDateImg;
  18. @property (nonatomic, strong) UIButton *sameButton;
  19. @end
  20. @implementation DRMyTicketCell
  21. + (instancetype)cellWithTableView:(UITableView *)tableView {
  22. static NSString *cellID = nil;
  23. cellID = NSStringFromClass([self class]);
  24. DRMyTicketCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  25. if (!cell) {
  26. cell = [[DRMyTicketCell 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.ticketImg addSubview:self.ticketLabel];
  53. [self.iconView addSubview:self.endDateImg];
  54. [self.contentView addSubview:self.sameButton];
  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.endDateImg 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(69);
  85. make.height.mas_equalTo(27);
  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:(DRMyTicketModel *)model {
  98. _model = model;
  99. [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.img]];
  100. self.titleLabel.text = model.title;
  101. self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  102. NSString *disPrice = [NSString stringWithFormat:@"¥%.2f",[model.price floatValue]];
  103. NSAttributedString *attr = [[NSAttributedString alloc] initWithString:disPrice attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11],
  104. NSForegroundColorAttributeName:[UIColor YHColorWithHex:0x999999],
  105. NSStrikethroughColorAttributeName:[UIColor YHColorWithHex:0x999999],
  106. NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid)}];
  107. self.disPriceLabel.attributedText = attr;
  108. if ([model.is_outdate boolValue]) {
  109. self.endDateLabel.text = @"已过期";
  110. self.endDateImg.hidden = NO;
  111. self.sameButton.hidden = NO;
  112. self.priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  113. self.ticketImg.hidden = YES;
  114. }else {
  115. self.endDateLabel.text = [NSString stringWithFormat:@"有效期至:%@",model.end_time];
  116. self.endDateImg.hidden = YES;
  117. self.sameButton.hidden = YES;
  118. self.priceLabel.textColor = [UIColor homeRedColor];
  119. self.ticketImg.hidden = NO;
  120. }
  121. }
  122. - (void)sameAction {
  123. if (self.saimarClick) {
  124. self.saimarClick();
  125. }
  126. }
  127. #pragma mark ------------------
  128. - (UIImageView *)iconView {
  129. if (!_iconView) {
  130. _iconView = [[UIImageView alloc] init];
  131. _iconView.backgroundColor = [UIColor yhGrayColor];
  132. }
  133. return _iconView;
  134. }
  135. - (UILabel *)titleLabel {
  136. if (!_titleLabel) {
  137. _titleLabel = [[UILabel alloc] init];
  138. _titleLabel.textColor = [UIColor YHColorWithHex:0x444444];
  139. _titleLabel.font = [UIFont systemFontOfSize:14];
  140. _titleLabel.numberOfLines = 2;
  141. }
  142. return _titleLabel;
  143. }
  144. - (UILabel *)endDateLabel {
  145. if (!_endDateLabel) {
  146. _endDateLabel = [[UILabel alloc] init];
  147. _endDateLabel.textColor = [UIColor YHColorWithHex:0x999999];
  148. _endDateLabel.font = [UIFont systemFontOfSize:11];
  149. }
  150. return _endDateLabel;
  151. }
  152. - (UILabel *)priceLabel {
  153. if (!_priceLabel) {
  154. _priceLabel = [[UILabel alloc] init];
  155. _priceLabel.font = [UIFont systemFontOfSize:15];
  156. _priceLabel.textColor = [UIColor homeRedColor];
  157. }
  158. return _priceLabel;
  159. }
  160. - (UILabel *)disPriceLabel {
  161. if (!_disPriceLabel) {
  162. _disPriceLabel = [[UILabel alloc] init];
  163. _disPriceLabel.font = [UIFont systemFontOfSize:11];
  164. _disPriceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  165. }
  166. return _disPriceLabel;
  167. }
  168. - (UIImageView *)ticketImg {
  169. if (!_ticketImg) {
  170. _ticketImg = [[UIImageView alloc] init];
  171. _ticketImg.image = [UIImage imageNamed:@"sale"];
  172. }
  173. return _ticketImg;
  174. }
  175. - (UILabel *)ticketLabel {
  176. if (!_ticketLabel) {
  177. _ticketLabel = [[UILabel alloc] init];
  178. _ticketLabel.textColor = [UIColor whiteColor];
  179. _ticketLabel.font = [UIFont systemFontOfSize:13];
  180. _ticketLabel.textAlignment = NSTextAlignmentCenter;
  181. _ticketLabel.backgroundColor = [UIColor clearColor];
  182. _ticketLabel.text = @"立即购买";
  183. }
  184. return _ticketLabel;
  185. }
  186. - (UILabel *)endDateImg {
  187. if (!_endDateImg) {
  188. _endDateImg = [[UILabel alloc] init];
  189. _endDateImg.text = @"已过期";
  190. _endDateImg.textAlignment = NSTextAlignmentCenter;
  191. _endDateImg.textColor = [UIColor whiteColor];
  192. _endDateImg.font = [UIFont systemFontOfSize:12];
  193. _endDateImg.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  194. }
  195. return _endDateImg;
  196. }
  197. - (UIButton *)sameButton {
  198. if (!_sameButton) {
  199. _sameButton = [UIButton buttonWithType:UIButtonTypeCustom];
  200. _sameButton.backgroundColor = [UIColor YHColorWithHex:0xFFAA31];
  201. [_sameButton setTitle:@"找相似" forState:UIControlStateNormal];
  202. _sameButton.titleLabel.textColor = [UIColor whiteColor];
  203. _sameButton.titleLabel.font = [UIFont systemFontOfSize:13];
  204. _sameButton.userInteractionEnabled = YES;
  205. [_sameButton addTarget:self action:@selector(sameAction) forControlEvents:UIControlEventTouchUpInside];
  206. }
  207. return _sameButton;
  208. }
  209. @end