ASHomeNewInCellTableViewCell.m 9.1 KB

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