ASHomeBestSellCell.m 7.0 KB

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