ASHomeTipCell.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // ASHomeTipCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/6.
  6. //
  7. #import "ASHomeTipCell.h"
  8. #import "ASHomeTipCollectCell.h"
  9. @interface ASHomeTipCell () <UICollectionViewDelegate,UICollectionViewDataSource>
  10. @property (nonatomic, strong) UICollectionView *collV;
  11. @property (nonatomic, strong) NSArray <NSString *>*titleArr;
  12. @property (nonatomic, strong) NSArray <NSString *>*imgArr;
  13. @end
  14. @implementation ASHomeTipCell
  15. - (void)setData {
  16. self.titleArr = [NSArray arrayWithObjects:@"USA UK CAN\nFREE SHIPPING",@"INTERNATIONAL\nEXPRESS SHIPPING",@"SECURE PAYMENTS\nCREDIT PAY IN 4",@"30 DAYS FREE\nRETURN/EXCHANGE", nil];
  17. self.imgArr = @[@"trade_tip",@"air_tip",@"pay_tip",@"box_tip"];
  18. [self.collV reloadData];
  19. }
  20. - (void)awakeFromNib {
  21. [super awakeFromNib];
  22. // Initialization code
  23. }
  24. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  25. [super setSelected:selected animated:animated];
  26. // Configure the view for the selected state
  27. }
  28. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  29. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  30. if (self) {
  31. self.contentView.backgroundColor = Col_FFF;
  32. self.backgroundColor = Col_FFF;
  33. self.selectionStyle = UITableViewCellSelectionStyleNone;
  34. [self.contentView addSubview:self.collV];
  35. CGFloat margin = 10;
  36. CGFloat w = (KScreenWidth- 3*margin-1)/2;
  37. CGFloat h = w/172*55;
  38. CGFloat colH = h*2 + margin+2;
  39. [self.collV mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.top.equalTo(self.contentView).offset(25);
  41. make.leading.trailing.equalTo(self.contentView);
  42. make.height.equalTo(@(colH));
  43. make.bottom.equalTo(self.contentView).offset(-25);
  44. }];
  45. [self setData];
  46. }
  47. return self;
  48. }
  49. - (UICollectionView *)collV {
  50. if (!_collV) {
  51. UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
  52. CGFloat margin = 10;
  53. CGFloat w = (KScreenWidth- 3*margin-1)/2;
  54. CGFloat h = w/172*55;
  55. CGFloat colH = h*2 + margin+2;
  56. layout.itemSize = CGSizeMake(w, h) ;
  57. layout.sectionInset = UIEdgeInsetsMake(0, margin, 0, margin);
  58. layout.minimumLineSpacing = margin;
  59. layout.minimumInteritemSpacing = margin;
  60. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  61. UICollectionView *col = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, colH) collectionViewLayout:layout];
  62. [col registerClass:[ASHomeTipCollectCell class] forCellWithReuseIdentifier:@"ASHomeTipCollectCell"];
  63. col.backgroundColor = UIColor.whiteColor;
  64. col.showsHorizontalScrollIndicator = false;
  65. col.delegate = self;
  66. col.dataSource = self;
  67. _collV = col;
  68. }
  69. return _collV;
  70. }
  71. // MARK: - coll delegate datasource
  72. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  73. return self.titleArr.count;
  74. }
  75. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  76. ASHomeTipCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASHomeTipCollectCell" forIndexPath:indexPath];
  77. if (self.titleArr.count <= indexPath.row) {
  78. return cell;
  79. }
  80. NSString *titleStr = self.titleArr[indexPath.row];
  81. NSString *imgName = self.imgArr[indexPath.row];
  82. cell.imgV.image = [UIImage imageNamed:imgName];
  83. cell.titleLb.text = titleStr;
  84. return cell;
  85. }
  86. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  87. }
  88. @end