HomeProblemTopCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // HomeProblemTopCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/19.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeProblemTopCell.h"
  9. #import "HomeProblemTopCollectCell.h"
  10. #import "NSDate+Extension.h"
  11. @interface HomeProblemTopCell()
  12. @property (nonatomic, strong) NSArray * dataArray;
  13. @end
  14. @implementation HomeProblemTopCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  20. [super setSelected:selected animated:animated];
  21. }
  22. + (HomeProblemTopCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  23. static NSString *cellIdentifer = @"HomeProblemTopCell0";
  24. HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  25. if (cell == nil) {
  26. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:0];
  27. }
  28. return cell;
  29. }
  30. + (HomeProblemTopCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  31. static NSString *cellIdentifer = @"HomeProblemTopCell1";
  32. HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  33. if (cell == nil) {
  34. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:1];
  35. }
  36. return cell;
  37. }
  38. - (void)setDataListModel:(HomeSubItemModel *)model
  39. {
  40. self.TitleL.text = model.Title;
  41. [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:kPlaceHolderImage];
  42. self.subTitleL.text = model.Summary;
  43. self.nameL.text = model.Author;
  44. self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
  45. self.keL.text = @"";
  46. self.timeL.text = [NSDate getMonthAndDayWihtDate:model.CreatedDate];
  47. }
  48. - (void)setDataModel:(BookProblemModel *)model
  49. {
  50. self.dataArray = model.ImageUrls.mutableCopy;
  51. self.collectH.constant = self.dataArray.count == 0 ? 0.f : 76.f;
  52. self.collectionView.delegate = self;
  53. self.collectionView.dataSource = self;
  54. self.collectionView.showsVerticalScrollIndicator = NO;
  55. self.collectionView.showsHorizontalScrollIndicator = NO;
  56. [self.collectionView registerNib:[UINib nibWithNibName:@"HomeProblemTopCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeProblemTopCollectCell"];
  57. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  58. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  59. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  60. [self.collectionView setCollectionViewLayout:layout];
  61. [self.collectionView setContentOffset:CGPointZero animated:NO];
  62. self.topTitleL.text = model.Title;
  63. self.topContentL.attributedText = [[NSAttributedString alloc] initWithString:model.Blocks];
  64. [self.collectionView reloadData];
  65. }
  66. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  67. {
  68. return 5.f;
  69. }
  70. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  71. {
  72. return 5.f;
  73. }
  74. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  75. {
  76. return self.dataArray.count;
  77. }
  78. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  79. {
  80. return 1;
  81. }
  82. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. return CGSizeMake(101, 76);
  85. }
  86. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  87. {
  88. NSString * imageStr = [self.dataArray objectAtIndex:indexPath.item];
  89. HomeProblemTopCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeProblemTopCollectCell" forIndexPath:indexPath];
  90. [cell setImageViewWithString:imageStr];
  91. return cell;
  92. }
  93. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  94. {
  95. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  96. WS(weakSelf);
  97. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  98. [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
  99. });
  100. }
  101. @end