BogoSearchVideoListCell.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // BogoSearchVideoListCell.m
  3. // BuguLive
  4. //
  5. // Created by Mac on 2021/9/27.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoSearchVideoListCell.h"
  9. #import "SmallVideoCell.h"
  10. @interface BogoSearchVideoListCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  11. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  12. @end
  13. @implementation BogoSearchVideoListCell
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. // Initialization code
  17. self.collectionView.delegate = self;
  18. self.collectionView.dataSource = self;
  19. [self.collectionView registerNib:[UINib nibWithNibName:@"SmallVideoCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"SmallVideoCell"];
  20. }
  21. - (void)setDataArray:(NSArray<SmallVideoListModel *> *)dataArray{
  22. _dataArray = dataArray;
  23. [self.collectionView reloadData];
  24. }
  25. #pragma mark - UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
  26. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  27. return 1;
  28. }
  29. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  30. return self.dataArray.count;
  31. }
  32. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  33. SmallVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SmallVideoCell" forIndexPath:indexPath];
  34. if (indexPath.item < self.dataArray.count) {
  35. [cell creatCellWithModel:self.dataArray[indexPath.item] andRow:(int)indexPath.item];
  36. }
  37. return cell;
  38. }
  39. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  40. CGFloat width = floor(( kScreenW - 25 ) / 2);
  41. return CGSizeMake(width, self.height - 25);
  42. }
  43. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  44. return UIEdgeInsetsMake(10, 10, 15, 10);
  45. }
  46. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  47. return 0;
  48. }
  49. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  50. return 5;
  51. }
  52. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  53. if (self.delegate && [self.delegate respondsToSelector:@selector(videoListCell:didClickVideo:)]) {
  54. [self.delegate videoListCell:self didClickVideo:self.dataArray[indexPath.item]];
  55. }
  56. }
  57. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  58. [super setSelected:selected animated:animated];
  59. // Configure the view for the selected state
  60. }
  61. @end