HomeWeiCousreCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // HomeWeiCousreCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/16.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeWeiCousreCell.h"
  9. #import "HomeWeiCousreCollectCell.h"
  10. #import "BookAlertModel.h"
  11. @implementation HomeWeiCousreCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. self.imgV.layer.cornerRadius = 2.5f;
  15. self.imgV.layer.masksToBounds = YES;
  16. }
  17. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  18. [super setSelected:selected animated:animated];
  19. // Configure the view for the selected state
  20. }
  21. + (HomeWeiCousreCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  22. static NSString *cellIdentifer = @"HomeWeiCousreCell0";
  23. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  24. if (cell == nil) {
  25. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:0];
  26. }
  27. return cell;
  28. }
  29. + (HomeWeiCousreCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  30. static NSString *cellIdentifer = @"HomeWeiCousreCell1";
  31. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  32. if (cell == nil) {
  33. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:1];
  34. }
  35. return cell;
  36. }
  37. + (HomeWeiCousreCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  38. static NSString *cellIdentifer = @"HomeWeiCousreCell2";
  39. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  40. if (cell == nil) {
  41. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:2];
  42. }
  43. return cell;
  44. }
  45. + (HomeWeiCousreCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  46. static NSString *cellIdentifer = @"HomeWeiCousreCell3";
  47. HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  48. if (cell == nil) {
  49. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:3];
  50. }
  51. return cell;
  52. }
  53. - (void)setCollData
  54. {
  55. self.collectionView.delegate = self;
  56. self.collectionView.dataSource = self;
  57. self.collectionView.showsVerticalScrollIndicator = NO;
  58. self.collectionView.showsHorizontalScrollIndicator = NO;
  59. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  60. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  61. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  62. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  63. [self.collectionView setCollectionViewLayout:layout];
  64. [self.collectionView setContentOffset:CGPointZero animated:NO];
  65. [self setArray];
  66. [self.collectionView reloadData];
  67. }
  68. - (void)setArray
  69. {
  70. self.dataArray = [NSMutableArray array];
  71. for (NSInteger i = 0 ; i < 8; i ++) {
  72. BookAlertModel * model = [[BookAlertModel alloc] init];
  73. model.title = @"高中生将面临5 种新考试!";
  74. model.isSelect = i == 0 ? YES : NO;
  75. [self.dataArray addObject:model];
  76. }
  77. }
  78. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  79. {
  80. return 15.f;
  81. }
  82. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  83. {
  84. return 15.f;
  85. }
  86. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  87. {
  88. return self.dataArray.count;
  89. }
  90. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  91. {
  92. return 1;
  93. }
  94. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  95. {
  96. return CGSizeMake(135, 80);
  97. }
  98. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. HomeWeiCousreCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeWeiCousreCollectCell" forIndexPath:indexPath];
  101. BookAlertModel * model = [self.dataArray objectAtIndex:indexPath.row];
  102. [cell setDataWithTitle:model.title isSelect:model.isSelect];
  103. return cell;
  104. }
  105. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  108. WS(weakSelf);
  109. BookAlertModel * model = [self.dataArray objectAtIndex:indexPath.row];
  110. for (BookAlertModel * smodel in self.dataArray) {
  111. smodel.isSelect = NO;
  112. }
  113. model.isSelect = YES;
  114. [self.collectionView reloadData];
  115. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  116. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  117. });
  118. }
  119. @end