ASHomeBestSellCell.m 7.3 KB

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