ASCategaryListCell.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // ASCategaryListCell.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/6/6.
  6. //
  7. #import "ASCategaryListCell.h"
  8. #import "ASCategaryCollectCell.h"
  9. #import "ASJumpModel.h"
  10. @interface ASCategaryListCell () <UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (nonatomic, strong) UICollectionView *collV;
  12. @end
  13. @implementation ASCategaryListCell
  14. - (void)setArr:(NSArray<ASJumpModel *> *)arr {
  15. _arr = arr;
  16. [self.collV reloadData];
  17. }
  18. - (void)awakeFromNib {
  19. [super awakeFromNib];
  20. // Initialization code
  21. }
  22. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  23. [super setSelected:selected animated:animated];
  24. // Configure the view for the selected state
  25. }
  26. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  27. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  28. if (self) {
  29. self.selectionStyle = UITableViewCellSelectionStyleNone;
  30. self.contentView.backgroundColor = UIColor.whiteColor;
  31. [self.contentView addSubview:self.collV];
  32. [self.collV mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.equalTo(self.contentView).offset(30);
  34. make.leading.trailing.equalTo(self.contentView);
  35. make.height.equalTo(@112);
  36. make.bottom.equalTo(self.contentView).offset(-25);
  37. }];
  38. }
  39. return self;
  40. }
  41. - (UICollectionView *)collV {
  42. if (!_collV) {
  43. UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
  44. layout.itemSize = CGSizeMake(112, 112);
  45. layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
  46. layout.minimumLineSpacing = 5;
  47. layout.minimumInteritemSpacing = 5;
  48. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  49. UICollectionView *col = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 112) collectionViewLayout:layout];
  50. [col registerClass:[ASCategaryCollectCell class] forCellWithReuseIdentifier:@"ASCategaryCollectCell"];
  51. col.showsHorizontalScrollIndicator = false;
  52. col.delegate = self;
  53. col.dataSource = self;
  54. col.backgroundColor = UIColor.whiteColor;
  55. _collV = col;
  56. }
  57. return _collV;
  58. }
  59. // MARK: - coll delegate datasource
  60. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  61. return _arr.count;
  62. }
  63. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  64. ASCategaryCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ASCategaryCollectCell" forIndexPath:indexPath];
  65. if (self.arr.count <= indexPath.row) {
  66. return cell;
  67. }
  68. ASJumpModel *m = self.arr[indexPath.row];
  69. [cell.imgV sd_setImageWithURL:[NSURL URLWithString:m.image]];
  70. cell.titleLb.text = m.title;
  71. return cell;
  72. }
  73. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  74. if (self.arr.count <= indexPath.row) {
  75. return ;
  76. }
  77. ASJumpModel *m = self.arr[indexPath.row];
  78. if (self.selectCategory) {
  79. self.selectCategory(m, indexPath);
  80. }
  81. }
  82. @end