ASHomeBestSellCell.m 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // ASHomeBestSellCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/6.
  6. //
  7. #import "ASHomeBestSellCell.h"
  8. #import "HomeFlashDealSubCollectCell.h"
  9. @interface ASHomeBestSellCell ()<UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
  10. @property (nonatomic, strong) UIView *bottomV;
  11. @property (nonatomic, strong) UIButton *moreBt;
  12. @end
  13. @implementation ASHomeBestSellCell
  14. - (void)setModel:(ASHomeMainListModel *)model {
  15. _model = model;
  16. self.titleLb.text = model.title;
  17. CGFloat lineH = (KScreenWidth-30)/2 + productHWithOutImg;
  18. NSInteger line = model.productList.count/2;
  19. line = line + (model.productList.count%2);
  20. CGFloat collH = (lineH + 10)*line + 10;
  21. [self.collectV mas_remakeConstraints:^(MASConstraintMaker *make) {
  22. make.left.equalTo(self.contentView).offset(0);
  23. make.right.equalTo(self.contentView).offset(-0);
  24. make.height.equalTo([NSNumber numberWithFloat:collH]);
  25. make.top.equalTo(self.titleLb.mas_bottom).offset(20);
  26. }];
  27. [self.collectV reloadData];
  28. }
  29. - (void)moreBtAction:(UIButton *)bt {
  30. if (self.moreClick) {
  31. self.moreClick(self.model);
  32. }
  33. }
  34. - (void)awakeFromNib {
  35. [super awakeFromNib];
  36. // Initialization code
  37. }
  38. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  39. [super setSelected:selected animated:animated];
  40. // Configure the view for the selected state
  41. }
  42. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  43. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  44. if (self) {
  45. [self loadSubV];
  46. }
  47. return self;
  48. }
  49. - (void)loadSubV {
  50. self.selectionStyle = UITableViewCellSelectionStyleNone;
  51. self.contentView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  52. self.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  53. [self.contentView addSubview:self.titleLb];
  54. [self.contentView addSubview:self.collectV];
  55. [self.contentView addSubview:self.bottomV];
  56. [self.bottomV addSubview:self.moreBt];
  57. [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.equalTo(self.contentView).offset(25);
  59. make.centerX.equalTo(self.contentView);
  60. make.left.greaterThanOrEqualTo(self.contentView).offset(20);
  61. make.height.equalTo(@30);
  62. }];
  63. CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg;
  64. [self.collectV mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.left.equalTo(self.contentView).offset(0);
  66. make.right.equalTo(self.contentView).offset(-0);
  67. make.height.equalTo([NSNumber numberWithFloat:collH]);
  68. make.top.equalTo(self.titleLb.mas_bottom).offset(20);
  69. }];
  70. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.centerX.equalTo(self.contentView);
  72. make.height.equalTo(@(20+36));
  73. make.leading.equalTo(self.contentView);
  74. make.top.equalTo(self.collectV.mas_bottom).offset(20);
  75. make.bottom.equalTo(self.contentView).offset(-40);
  76. }];
  77. [self.moreBt mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.width.equalTo(@200);
  79. make.height.equalTo(@36);
  80. make.centerX.equalTo(self.bottomV);
  81. make.centerY.equalTo(self.bottomV);
  82. }];
  83. }
  84. // MARK: - delegate datasource
  85. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  86. if (self.productClick) {
  87. ASProductBaseModel *m = self.model.productList[indexPath.row];
  88. self.productClick(indexPath.row, m);
  89. }
  90. }
  91. // MARK: - UICollectionViewDataSource
  92. - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  93. HomeFlashDealSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell" forIndexPath:indexPath];
  94. if (self.model.productList.count <= indexPath.row)
  95. {
  96. return cell;
  97. }
  98. ASProductBaseModel *m = self.model.productList[indexPath.row];
  99. cell.model = m;
  100. cell.contView.addCartBt.hidden = true;
  101. return cell;
  102. }
  103. - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  104. return self.model.productList.count;
  105. }
  106. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  107. CGFloat marg = 10;
  108. CGFloat w = (KScreenWidth-3*marg)/2;
  109. CGFloat collH = (KScreenWidth-30)/2 + productHWithOutImg;
  110. return CGSizeMake(w, collH);
  111. }
  112. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  113. return 10;
  114. }
  115. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  116. return 10;
  117. }
  118. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  119. return UIEdgeInsetsMake(10, 10, 10, 10);
  120. }
  121. - (UILabel *)titleLb {
  122. if (!_titleLb) {
  123. UILabel *lb = [[UILabel alloc] init];
  124. lb.textColor = [UIColor blackColor];
  125. lb.font = [UIFont fontWithName:Rob_Bold size:24];
  126. lb.textAlignment = NSTextAlignmentCenter;
  127. _titleLb = lb;
  128. }
  129. return _titleLb;
  130. }
  131. -(UICollectionView *)collectV {
  132. if (!_collectV) {
  133. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  134. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  135. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  136. CGFloat collH = (KScreenWidth-30)/2 + 126;
  137. layout.itemSize = CGSizeMake((KScreenWidth - 30)/2, collH);
  138. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout];
  139. collV.backgroundColor = [UIColor whiteColor];
  140. collV.alwaysBounceHorizontal = true;
  141. collV.scrollEnabled = false;
  142. collV.delegate = self;
  143. collV.dataSource = self;
  144. collV.showsHorizontalScrollIndicator = false;
  145. [collV registerClass:[HomeFlashDealSubCollectCell class] forCellWithReuseIdentifier:@"HomeFlashDealSubCollectCell"];
  146. _collectV = collV;
  147. }
  148. return _collectV;
  149. }
  150. -(UIView *)bottomV {
  151. if (!_bottomV) {
  152. UIView *v = [UIView baseV];
  153. v.backgroundColor = Col_FFF;
  154. v.clipsToBounds = true;
  155. _bottomV = v;
  156. }
  157. return _bottomV;
  158. }
  159. - (UIButton *)moreBt {
  160. if (!_moreBt) {
  161. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  162. [bt setTitle:@"VIEW MORE" forState:UIControlStateNormal];
  163. [bt setTitleColor:Col_000 forState:UIControlStateNormal];
  164. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  165. bt.layer.cornerRadius = 4;
  166. bt.layer.borderColor = Col_000.CGColor;
  167. bt.layer.borderWidth = 1;
  168. bt.layer.masksToBounds = true;
  169. [bt addTarget:self action:@selector(moreBtAction:) forControlEvents:UIControlEventTouchUpInside];
  170. _moreBt = bt;
  171. }
  172. return _moreBt;
  173. }
  174. @end