JXVipCenterView.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // JXVipCenterView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/30.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXVipCenterView.h"
  9. #import "JXVipDetailCCell.h"
  10. @interface JXVipCenterView()<UICollectionViewDelegate,UICollectionViewDataSource>
  11. @property (nonatomic,weak) UICollectionView *collectionView;
  12. @end
  13. @implementation JXVipCenterView
  14. //+(instancetype)XIBJXJXVipCenterView{
  15. //
  16. // return [[NSBundle mainBundle]loadNibNamed:@"JXVipCenterView" owner:self options:nil].firstObject;
  17. //}
  18. -(void)setDataArr:(NSMutableArray *)dataArr{
  19. _dataArr=dataArr;
  20. [_collectionView reloadData];
  21. }
  22. -(instancetype)initWithFrame:(CGRect)frame{
  23. if (self=[super initWithFrame:frame]) {
  24. _dataArr=[NSMutableArray array];
  25. UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
  26. flowLayout.minimumInteritemSpacing = 10;
  27. flowLayout.minimumLineSpacing = 10;
  28. flowLayout.sectionInset = UIEdgeInsetsMake(15, 60, 5, 15);
  29. flowLayout.itemSize = CGSizeMake(JX_SCREEN_WIDTH - 110, 120);
  30. flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  31. UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 120) collectionViewLayout:flowLayout];
  32. collectionView.delegate = self;
  33. collectionView.dataSource = self;
  34. collectionView.backgroundColor=[UIColor whiteColor];
  35. self.collectionView=collectionView;
  36. [self addSubview:collectionView];
  37. [collectionView registerNib:[UINib nibWithNibName:@"JXVipDetailCCell" bundle:nil] forCellWithReuseIdentifier:@"JXVipDetailCCell"];
  38. [collectionView reloadData];
  39. }
  40. return self;
  41. }
  42. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  43. return _dataArr.count;
  44. }
  45. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  46. JXVipDetailCCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"JXVipDetailCCell" forIndexPath:indexPath];
  47. cell.layer.cornerRadius=15;
  48. cell.layer.masksToBounds=YES;
  49. vipDetailModel *model=_dataArr[indexPath.row];
  50. cell.model=model;
  51. return cell;
  52. }
  53. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  54. if ([_delegate respondsToSelector:@selector(jxScrollViewDidScroll:)]) {
  55. [self.delegate jxScrollViewDidScroll:scrollView];
  56. }
  57. }
  58. @end