ASHomeNewInCellTableViewCell.m 8.7 KB

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