ASHomeNewInCellTableViewCell.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // ASHomeNewInCellTableViewCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/9.
  6. //
  7. #import "ASHomeNewInCellTableViewCell.h"
  8. #import "KWScrollOffsetView.h"
  9. #import "ASHomeNewInSubCollectCell.h"
  10. @interface ASHomeNewInCellTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  11. @property (nonatomic, strong) UIView *colorBgV;
  12. @property (nonatomic, strong) UICollectionView *collectV;
  13. @property (nonatomic, strong) UILabel *titleLb;
  14. @property (nonatomic, strong) KWScrollOffsetView *offsetV;
  15. @property (nonatomic, strong) UIView *bottomV;
  16. @property (nonatomic, strong) UIButton *moreBt;
  17. @property (nonatomic, strong) ASHomeMainListModel *model;
  18. @end
  19. @implementation ASHomeNewInCellTableViewCell
  20. -(void)setData:(ASHomeMainListModel *)model {
  21. self.model = model;
  22. self.titleLb.text = self.model.title;
  23. self.offsetV.hidden = model.productList.count <= 1;
  24. [self.collectV reloadData];
  25. }
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. // Initialization code
  29. }
  30. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  31. [super setSelected:selected animated:animated];
  32. // Configure the view for the selected state
  33. }
  34. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  35. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  36. if (self) {
  37. [self loadSubV];
  38. }
  39. return self;
  40. }
  41. - (void)loadSubV {
  42. self.selectionStyle = UITableViewCellSelectionStyleNone;
  43. self.contentView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  44. self.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
  45. self.offsetV.backgroundColor = _B1B1B1;
  46. self.offsetV.offsetV.backgroundColor = Col_FFF;
  47. [self.contentView addSubview:self.colorBgV];
  48. [self.colorBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  49. make.edges.equalTo(self.contentView);
  50. }];
  51. [self.contentView addSubview:self.titleLb];
  52. [self.contentView addSubview:self.collectV];
  53. [self.contentView addSubview:self.offsetV];
  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(50);
  58. make.centerX.equalTo(self.contentView);
  59. make.left.greaterThanOrEqualTo(self.contentView).offset(20);
  60. make.height.equalTo(@30);
  61. make.width.greaterThanOrEqualTo(@80);
  62. }];
  63. CGFloat collH = (KScreenWidth-20) + productHWithOutImg+10;
  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(30);
  69. }];
  70. [self.offsetV mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.centerX.equalTo(self.contentView);
  72. make.height.equalTo(@2);
  73. make.width.equalTo(@137);
  74. make.top.equalTo(self.collectV.mas_bottom).offset(11);
  75. }];
  76. [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.centerX.equalTo(self.contentView);
  78. make.height.equalTo(@(20+36));
  79. make.leading.equalTo(self.contentView);
  80. make.top.equalTo(self.offsetV.mas_bottom).offset(20);
  81. make.bottom.equalTo(self.contentView).offset(-40);
  82. }];
  83. [self.moreBt mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.width.equalTo(@200);
  85. make.height.equalTo(@36);
  86. make.centerX.equalTo(self.bottomV);
  87. make.centerY.equalTo(self.bottomV);
  88. }];
  89. dispatch_async(dispatch_get_main_queue(), ^{
  90. [UIView viewAddHorColorBg:self.colorBgV colorArr:@[
  91. (id)(_043632.CGColor),
  92. (id)(_0E0E0F.CGColor),
  93. ] startP:CGPointMake(0.5, 0.1) endP:CGPointMake(0.5, 1)];
  94. });
  95. }
  96. // MARK: - UICollectionViewDelegate
  97. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  98. if (self.offsetV.isHidden) {
  99. return;
  100. }
  101. CGFloat offset = scrollView.contentOffset.x;
  102. CGFloat itemWidth = (KScreenWidth-20);
  103. NSArray<ASProductBaseModel*> *arr = self.model.productList;
  104. if (arr.count > 0) {
  105. CGFloat maxOffset = (arr.count * (itemWidth + 10) - 10 ) - (KScreenWidth-20);
  106. self.offsetV.offset = offset/maxOffset;
  107. }
  108. }
  109. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  110. if (self.productClick) {
  111. NSArray<ASProductBaseModel*> *arr = self.model.productList;
  112. ASProductBaseModel *m = arr[indexPath.row];
  113. self.productClick(indexPath.row, m);
  114. }
  115. }
  116. // MARK: - UICollectionViewDataSource
  117. - (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
  118. ASHomeNewInSubCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASHomeNewInSubCollectCell" forIndexPath:indexPath];
  119. NSArray<ASProductBaseModel*> *arr = self.model.productList;
  120. ASProductBaseModel *m = arr[indexPath.row];
  121. cell.model = m;
  122. __weak typeof(self) weakSelf = self;
  123. cell.contView.addCartBlock = ^(ASProductBaseModel * _Nonnull model) {
  124. if (weakSelf.addCartBlock) {
  125. weakSelf.addCartBlock(indexPath.row, model);
  126. }
  127. };
  128. return cell;
  129. }
  130. - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  131. NSArray<ASProductBaseModel*> *arr = self.model.productList;
  132. return arr.count;
  133. }
  134. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  135. CGFloat marg = 10;
  136. CGFloat w = (KScreenWidth-2*marg);
  137. CGFloat collH = (KScreenWidth-20) + productHWithOutImg+10;
  138. return CGSizeMake(w, collH);
  139. }
  140. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  141. return 10;
  142. }
  143. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  144. return 10;
  145. }
  146. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  147. return UIEdgeInsetsMake(0, 10, 0, 10);
  148. }
  149. // MARK: - subvs
  150. - (UILabel *)titleLb {
  151. if (!_titleLb) {
  152. UILabel *lb = [[UILabel alloc] init];
  153. lb.textColor = [UIColor whiteColor];
  154. lb.font = [UIFont fontWithName:Rob_Bold size:24];
  155. lb.textAlignment = NSTextAlignmentCenter;
  156. _titleLb = lb;
  157. }
  158. return _titleLb;
  159. }
  160. - (KWScrollOffsetView *)offsetV {
  161. if (!_offsetV) {
  162. KWScrollOffsetView *v = [[KWScrollOffsetView alloc] initWithFrame:CGRectMake(0, 0, 137, 2)];
  163. v.clipsToBounds = true;
  164. v.offWidth = 54;
  165. v.offset = 0;
  166. _offsetV = v;
  167. }
  168. return _offsetV;
  169. }
  170. -(UICollectionView *)collectV {
  171. if (!_collectV) {
  172. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  173. layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
  174. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  175. CGFloat collH = (KScreenWidth-30)/2 + 126;
  176. layout.itemSize = CGSizeMake((KScreenWidth - 30)/2, collH);
  177. UICollectionView *collV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, collH) collectionViewLayout:layout];
  178. collV.backgroundColor = [UIColor clearColor];
  179. collV.alwaysBounceHorizontal = true;
  180. // collV.pagingEnabled = true;
  181. collV.delegate = self;
  182. collV.dataSource = self;
  183. collV.showsHorizontalScrollIndicator = false;
  184. [collV registerClass:[ASHomeNewInSubCollectCell class] forCellWithReuseIdentifier:@"ASHomeNewInSubCollectCell"];
  185. _collectV = collV;
  186. }
  187. return _collectV;
  188. }
  189. -(UIView *)bottomV {
  190. if (!_bottomV) {
  191. UIView *v = [UIView baseV];
  192. v.backgroundColor = UIColor.clearColor;
  193. v.clipsToBounds = true;
  194. _bottomV = v;
  195. }
  196. return _bottomV;
  197. }
  198. - (UIButton *)moreBt {
  199. if (!_moreBt) {
  200. UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
  201. [bt setTitle:@"VIEW MORE" forState:UIControlStateNormal];
  202. [bt setTitleColor:Col_FFF forState:UIControlStateNormal];
  203. bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  204. bt.layer.cornerRadius = 4;
  205. bt.layer.borderColor = Col_FFF.CGColor;
  206. bt.layer.borderWidth = 1;
  207. bt.layer.masksToBounds = true;
  208. _moreBt = bt;
  209. }
  210. return _moreBt;
  211. }
  212. - (UIView *)colorBgV {
  213. if (!_colorBgV) {
  214. UIView *v = [UIView baseV];
  215. v.backgroundColor = _043632;
  216. _colorBgV = v;
  217. }
  218. return _colorBgV;
  219. }
  220. @end