HomeBigshotCell.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // HomeBigshotCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/13.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeBigshotCell.h"
  9. #import "HomeBigshotCollectCell.h"
  10. #import "HomeBigshotListCell.h"
  11. @interface HomeBigshotCell()
  12. @property (nonatomic, assign) NSInteger type;
  13. @end
  14. @implementation HomeBigshotCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. self.collectionView.delegate = self;
  18. self.collectionView.dataSource = self;
  19. self.collectionView.showsVerticalScrollIndicator = NO;
  20. self.collectionView.showsHorizontalScrollIndicator = NO;
  21. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotCollectCell"];
  22. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeBigshotListCell" bundle:nil] forCellWithReuseIdentifier:@"HomeBigshotListCell"];
  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. + (HomeBigshotCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  29. static NSString *cellIdentifer = @"HomeBigshotCell0";
  30. HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  31. if (cell == nil) {
  32. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:0];
  33. }
  34. return cell;
  35. }
  36. + (HomeBigshotCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  37. static NSString *cellIdentifer = @"HomeBigshotCell1";
  38. HomeBigshotCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  39. if (cell == nil) {
  40. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeBigshotCell" owner:nil options:nil] objectAtIndex:1];
  41. }
  42. return cell;
  43. }
  44. - (void)setDatatype:(NSInteger)type
  45. {
  46. self.type = type;
  47. if (self.type == 0) {
  48. self.collectionView.scrollEnabled = YES;
  49. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  50. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  51. layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
  52. [self.collectionView setCollectionViewLayout:layout];
  53. [self.collectionView setContentOffset:CGPointZero animated:NO];
  54. }else{
  55. self.height.constant = 20 * 110.f;
  56. self.collectionView.scrollEnabled = NO;
  57. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  58. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  59. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  60. [self.collectionView setCollectionViewLayout:layout];
  61. [self.collectionView setContentOffset:CGPointZero animated:NO];
  62. }
  63. [self.collectionView reloadData];
  64. }
  65. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  66. {
  67. return self.type == 0 ? 0.f:10.f;
  68. }
  69. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  70. {
  71. return self.type == 0 ? 0.f:10.f;
  72. }
  73. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  74. {
  75. return self.type == 0 ? 3 : 20;
  76. }
  77. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  78. {
  79. return 1;
  80. }
  81. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  82. {
  83. if (self.type == 0) {
  84. return CGSizeMake(130, 175);
  85. }else{
  86. return CGSizeMake(SCREEN_WIDTH, 110);
  87. }
  88. }
  89. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. if (self.type == 0) {
  92. HomeBigshotCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotCollectCell" forIndexPath:indexPath];
  93. return cell;
  94. }else{
  95. HomeBigshotListCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeBigshotListCell" forIndexPath:indexPath];
  96. return cell;
  97. }
  98. }
  99. @end