HomeWeiCousreCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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)setDataWithModel:(HomeSubItemModel *)model
  54. {
  55. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  56. self.titleL.text = model.Title;
  57. self.subTitleL.text = model.Summary;
  58. self.nameL.text = model.Author;
  59. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  60. }
  61. - (void)setDataVideoModel:(BookChanelRightModel *)model
  62. {
  63. [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
  64. self.titleL.text = model.Title;
  65. self.subTitleL.text = model.Summary;
  66. self.nameL.text = model.Author;
  67. self.playTimeL.text = model.Duration;
  68. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  69. }
  70. - (void)setDataRightModel:(BookChanelRightModel *)model
  71. {
  72. self.titleL.text = model.Name;
  73. self.subTitleL.text = model.ExpandName;
  74. }
  75. - (void)setCollData
  76. {
  77. self.collectionView.delegate = self;
  78. self.collectionView.dataSource = self;
  79. self.collectionView.showsVerticalScrollIndicator = NO;
  80. self.collectionView.showsHorizontalScrollIndicator = NO;
  81. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
  82. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  83. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  84. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  85. [self.collectionView setCollectionViewLayout:layout];
  86. [self.collectionView setContentOffset:CGPointZero animated:NO];
  87. [self setArray];
  88. [self.collectionView reloadData];
  89. }
  90. - (void)setArray
  91. {
  92. self.dataArray = [NSMutableArray array];
  93. for (NSInteger i = 0 ; i < 8; i ++) {
  94. BookAlertModel * model = [[BookAlertModel alloc] init];
  95. model.title = @"高中生将面临5 种新考试!";
  96. model.isSelect = i == 0 ? YES : NO;
  97. [self.dataArray addObject:model];
  98. }
  99. }
  100. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  101. {
  102. return 15.f;
  103. }
  104. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  105. {
  106. return 15.f;
  107. }
  108. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  109. {
  110. return self.dataArray.count;
  111. }
  112. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  113. {
  114. return 1;
  115. }
  116. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. return CGSizeMake(135, 80);
  119. }
  120. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  121. {
  122. HomeWeiCousreCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeWeiCousreCollectCell" forIndexPath:indexPath];
  123. BookAlertModel * model = [self.dataArray objectAtIndex:indexPath.row];
  124. [cell setDataWithTitle:model.title isSelect:model.isSelect];
  125. return cell;
  126. }
  127. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  128. {
  129. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  130. WS(weakSelf);
  131. BookAlertModel * model = [self.dataArray objectAtIndex:indexPath.row];
  132. for (BookAlertModel * smodel in self.dataArray) {
  133. smodel.isSelect = NO;
  134. }
  135. model.isSelect = YES;
  136. [self.collectionView reloadData];
  137. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  138. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  139. });
  140. }
  141. @end