线上所有马甲包模板,与《猎豆》同UI。域名zhuadd

HSQTimeLineTopView.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // HSQTimeLineTopView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2019/1/3.
  6. // Copyright © 2019年 kuxuan. All rights reserved.
  7. //
  8. #import "HSQTimeLineTopView.h"
  9. #import "HSQTimeLineChannelCell.h"
  10. @interface HSQTimeLineTopView ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
  11. @property (nonatomic, strong) UICollectionView *collectionView;
  12. @property (nonatomic, strong) NSMutableArray *dataArr;
  13. @end
  14. static NSString *cellID = @"cellID";
  15. @implementation HSQTimeLineTopView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initSubViews];
  21. }
  22. return self;
  23. }
  24. - (void)initSubViews {
  25. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  26. flowLayout.minimumLineSpacing = 0;
  27. flowLayout.minimumInteritemSpacing = 0;
  28. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  29. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height) collectionViewLayout:flowLayout];
  30. self.collectionView.backgroundColor = [UIColor whiteColor];
  31. self.collectionView.showsVerticalScrollIndicator = NO;
  32. self.collectionView.showsHorizontalScrollIndicator = NO;
  33. [self.collectionView registerClass:[HSQTimeLineChannelCell class] forCellWithReuseIdentifier:cellID];
  34. self.collectionView.delegate = self;
  35. self.collectionView.dataSource = self;
  36. if (@available(iOS 11.0, *)) {
  37. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  38. }
  39. [self addSubview: self.collectionView];
  40. }
  41. - (void)setData:(NSArray *)data {
  42. self.dataArr = data.mutableCopy;
  43. [self.collectionView reloadData];
  44. }
  45. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  46. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  47. {
  48. return self.dataArr.count;
  49. }
  50. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  51. return CGSizeMake(88, 130);
  52. }
  53. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  54. {
  55. return CGSizeMake(0, 0);
  56. }
  57. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  58. {
  59. return CGSizeMake(0, 0);
  60. }
  61. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  62. {
  63. HSQTimeLineChannelCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  64. HSQTimeLineChannelModel *model = self.dataArr[indexPath.row];
  65. cell.model = model;
  66. return cell;
  67. }
  68. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  69. return UIEdgeInsetsMake(0, 10, 0, 10);
  70. }
  71. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  72. }
  73. @end