猎豆优选

LDOnePicCell.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. //
  2. // LDOnePicCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/1/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDOnePicCell.h"
  9. @interface LDOnePicCell ()
  10. @property (nonatomic, strong) UIImageView *imgView;
  11. @property (nonatomic, strong) UILabel *titleLabel;
  12. @property (nonatomic, strong) UILabel *countLabel;
  13. @property (nonatomic, strong) UILabel *desLabel;
  14. @property (nonatomic, strong) UILabel *priceLabel;
  15. @property (nonatomic, strong) UIImageView *ticketImg;
  16. @property (nonatomic, strong) UILabel *ticketPrice;
  17. @property (nonatomic, strong) UILabel *saleCount;
  18. @property (nonatomic, strong) UIImageView *ticketNumber;
  19. @property (nonatomic, strong) UIView *line;
  20. @property (nonatomic, strong) UILabel *zheKou;
  21. @property (nonatomic, strong) UILabel *typeLabel;
  22. @property (nonatomic, strong) UIImageView *isNew;
  23. @property (nonatomic, strong) UILabel *numLabel;
  24. @end
  25. @implementation LDOnePicCell
  26. + (instancetype)cellWithTableView:(UITableView *)tableView {
  27. static NSString *cellID = nil;
  28. cellID = NSStringFromClass([self class]);
  29. LDOnePicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  30. if (!cell) {
  31. cell = [[LDOnePicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  32. }
  33. return cell;
  34. }
  35. - (void)awakeFromNib {
  36. [super awakeFromNib];
  37. // Initialization code
  38. }
  39. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  40. [super setSelected:selected animated:animated];
  41. // Configure the view for the selected state
  42. }
  43. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  44. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  45. if (self) {
  46. self.selectionStyle = UITableViewCellSelectionStyleNone;
  47. [self initSubViews];
  48. }
  49. return self;
  50. }
  51. - (void)initSubViews {
  52. [self.contentView addSubview:self.imgView];
  53. [self.imgView addSubview:self.isNew];
  54. [self.contentView addSubview:self.titleLabel];
  55. [self.contentView addSubview:self.countLabel];
  56. [self.contentView addSubview:self.desLabel];
  57. [self.contentView addSubview:self.priceLabel];
  58. [self.contentView addSubview:self.saleCount];
  59. [self.contentView addSubview:self.ticketImg];
  60. [self.ticketImg addSubview:self.typeLabel];
  61. [self.contentView addSubview:self.ticketPrice];
  62. [self.contentView addSubview:self.ticketNumber];
  63. [self.contentView addSubview:self.line];
  64. [self.ticketNumber addSubview:self.zheKou];
  65. [self.imgView addSubview:self.numLabel];
  66. [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.top.mas_equalTo(0);
  68. make.width.height.mas_equalTo(Fitsize(152));
  69. }];
  70. [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.left.right.bottom.mas_equalTo(0);
  72. make.height.mas_equalTo(20);
  73. }];
  74. [self.isNew mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.left.mas_equalTo(0);
  76. make.top.mas_equalTo(10);
  77. make.width.mas_equalTo(45);
  78. make.height.mas_equalTo(19);
  79. }];
  80. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.mas_equalTo(self.imgView.mas_right).mas_offset(10);
  82. make.top.mas_equalTo(10);
  83. make.right.mas_equalTo(-10);
  84. }];
  85. [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.mas_equalTo(self.titleLabel.mas_left);
  87. make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(7);
  88. make.right.mas_equalTo(self.titleLabel.mas_right);
  89. }];
  90. [self.desLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.mas_equalTo(self.titleLabel.mas_left);
  92. make.top.mas_equalTo(self.countLabel.mas_bottom).mas_offset(7);
  93. make.right.mas_equalTo(self.titleLabel.mas_right);
  94. }];
  95. [self.ticketImg mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.mas_equalTo(self.titleLabel.mas_left);
  97. make.bottom.mas_equalTo(Fitsize(-20));
  98. make.width.mas_equalTo(34);
  99. make.height.mas_equalTo(18);
  100. }];
  101. [self.typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.right.top.bottom.mas_equalTo(0);
  103. }];
  104. [self.ticketPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.left.mas_equalTo(self.ticketImg.mas_right).mas_offset(5);
  106. make.centerY.mas_equalTo(self.ticketImg.mas_centerY);
  107. }];
  108. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  109. make.right.mas_equalTo(-10);
  110. make.centerY.mas_equalTo(self.ticketImg.mas_centerY);
  111. make.width.mas_equalTo(64);
  112. make.height.mas_equalTo(22);
  113. }];
  114. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.top.bottom.left.right.mas_equalTo(0);
  116. }];
  117. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.mas_equalTo(self.titleLabel.mas_left);
  119. make.bottom.mas_equalTo(self.ticketImg.mas_top).mas_offset(-10);
  120. }];
  121. [self.saleCount mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.right.mas_equalTo(-10);
  123. make.centerY.mas_equalTo(self.priceLabel.mas_centerY);
  124. }];
  125. [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.mas_equalTo(self.titleLabel.mas_left);
  127. make.bottom.mas_equalTo(-5);
  128. make.height.mas_equalTo(0.5);
  129. make.right.mas_equalTo(-5);
  130. }];
  131. }
  132. - (void)setModel:(LDChildGoodModel *)model {
  133. _model = model;
  134. [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:Placehold_Img];
  135. self.titleLabel.text = model.title;
  136. self.priceLabel.text = [NSString stringWithFormat:@"淘宝价 ¥%.2f",[model.price floatValue]];
  137. self.saleCount.text = [NSString stringWithFormat:@"月销%@",model.volume];
  138. self.ticketPrice.text = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  139. //折后价
  140. if (model.is_coupon) {
  141. self.typeLabel.text = @"券后价";
  142. self.zheKou.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
  143. }else {
  144. self.typeLabel.text = @"折后价";
  145. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  146. }
  147. if ([model.type isEqualToString:@"1"]) {
  148. self.numLabel.hidden = NO;
  149. self.numLabel.text = [NSString stringWithFormat:@"共%@件",model.coupon_surplus];
  150. }else {
  151. self.numLabel.hidden = YES;
  152. }
  153. self.isNew.hidden = ![model.is_new boolValue];
  154. }
  155. #pragma mark =============== layzer =================
  156. - (UIImageView *)imgView {
  157. if (!_imgView) {
  158. _imgView = [[UIImageView alloc] init];
  159. _imgView.backgroundColor = [UIColor yhGrayColor];
  160. }
  161. return _imgView;
  162. }
  163. - (UILabel *)titleLabel {
  164. if (!_titleLabel) {
  165. _titleLabel = [[UILabel alloc] init];
  166. _titleLabel.text = @"哈密瓜哈密瓜哈密瓜哈密瓜哈密瓜";
  167. _titleLabel.font = [UIFont systemFontOfSize:15];
  168. _titleLabel.numberOfLines = 2;
  169. _titleLabel.textColor = [UIColor YHColorWithHex:0x222222];
  170. }
  171. return _titleLabel;
  172. }
  173. - (UILabel *)countLabel {
  174. if (!_countLabel) {
  175. _countLabel = [[UILabel alloc] init];
  176. _countLabel.font = [UIFont systemFontOfSize:15];
  177. _countLabel.textColor = [UIColor YHColorWithHex:0x222222];
  178. }
  179. return _countLabel;
  180. }
  181. - (UILabel *)desLabel {
  182. if (!_desLabel) {
  183. _desLabel = [[UILabel alloc] init];
  184. _desLabel.textColor = [UIColor homeRedColor];
  185. _desLabel.font = [UIFont systemFontOfSize:13];
  186. }
  187. return _desLabel;
  188. }
  189. - (UILabel *)priceLabel {
  190. if (!_priceLabel) {
  191. _priceLabel = [[UILabel alloc] init];
  192. _priceLabel.font = [UIFont systemFontOfSize:12];
  193. _priceLabel.textColor = [UIColor YHColorWithHex:0x999999];
  194. }
  195. return _priceLabel;
  196. }
  197. - (UILabel *)saleCount {
  198. if (!_saleCount) {
  199. _saleCount = [[UILabel alloc] init];
  200. _saleCount.font = [UIFont systemFontOfSize:12];
  201. _saleCount.textColor = [UIColor YHColorWithHex:0x999999];
  202. _saleCount.textAlignment = NSTextAlignmentRight;
  203. }
  204. return _saleCount;
  205. }
  206. - (UIImageView *)ticketImg {
  207. if (!_ticketImg) {
  208. _ticketImg = [[UIImageView alloc] init];
  209. _ticketImg.image = [UIImage imageNamed:@"sale"];
  210. }
  211. return _ticketImg;
  212. }
  213. - (UILabel *)ticketPrice {
  214. if (!_ticketPrice) {
  215. _ticketPrice = [[UILabel alloc] init];
  216. _ticketPrice.textColor = [UIColor homeRedColor];
  217. _ticketPrice.font = [UIFont boldSystemFontOfSize:17];
  218. }
  219. return _ticketPrice;
  220. }
  221. - (UIImageView *)ticketNumber {
  222. if (!_ticketNumber) {
  223. _ticketNumber = [[UIImageView alloc] init];
  224. _ticketNumber.image = [UIImage imageNamed:@"discount"];
  225. }
  226. return _ticketNumber;
  227. }
  228. - (UILabel *)zheKou {
  229. if (!_zheKou) {
  230. _zheKou = [[UILabel alloc] init];
  231. _zheKou.textColor = [UIColor whiteColor];
  232. _zheKou.textAlignment = NSTextAlignmentCenter;
  233. _zheKou.font = [UIFont systemFontOfSize:13];
  234. _zheKou.backgroundColor = [UIColor clearColor];
  235. }
  236. return _zheKou;
  237. }
  238. - (UILabel *)typeLabel {
  239. if (!_typeLabel) {
  240. _typeLabel = [[UILabel alloc] init];
  241. _typeLabel.textColor = [UIColor whiteColor];
  242. _typeLabel.font = [UIFont systemFontOfSize:10];
  243. _typeLabel.textAlignment = NSTextAlignmentCenter;
  244. }
  245. return _typeLabel;
  246. }
  247. - (UIView *)line {
  248. if (!_line) {
  249. _line = [[UIView alloc] init];
  250. _line.backgroundColor = [UIColor YHColorWithHex:0xcccccc];
  251. }
  252. return _line;
  253. }
  254. - (UIImageView *)isNew {
  255. if (!_isNew) {
  256. _isNew = [[UIImageView alloc] init];
  257. _isNew.image = [UIImage imageNamed:@"new"];
  258. }
  259. return _isNew;
  260. }
  261. - (UILabel *)numLabel {
  262. if (!_numLabel) {
  263. _numLabel = [[UILabel alloc] init];
  264. _numLabel.textColor = [UIColor whiteColor];
  265. _numLabel.textAlignment = NSTextAlignmentCenter;
  266. _numLabel.font = [UIFont systemFontOfSize:11];
  267. _numLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
  268. }
  269. return _numLabel;
  270. }
  271. @end