123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // HomeProblemTopCell.m
- // smartRhino
- //
- // Created by niuzhen on 2020/5/19.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeProblemTopCell.h"
- #import "HomeProblemTopCollectCell.h"
- #import "NSDate+Extension.h"
- @interface HomeProblemTopCell()
- @property (nonatomic, strong) NSArray * dataArray;
- @end
- @implementation HomeProblemTopCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- }
- + (HomeProblemTopCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeProblemTopCell0";
- HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:0];
- }
- return cell;
- }
- + (HomeProblemTopCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeProblemTopCell1";
- HomeProblemTopCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeProblemTopCell" owner:nil options:nil] objectAtIndex:1];
- }
- return cell;
- }
- - (void)setDataListModel:(HomeSubItemModel *)model
- {
- self.TitleL.text = model.Title;
- [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:kPlaceHolderImage];
- self.subTitleL.text = model.Summary;
- self.nameL.text = model.Author;
- self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- self.keL.text = @"";
- self.timeL.text = [NSDate getMonthAndDayWihtDate:model.CreatedDate];
- }
- - (void)setDataModel:(BookProblemModel *)model
- {
- self.dataArray = model.ImageUrls.mutableCopy;
- self.collectH.constant = self.dataArray.count == 0 ? 0.f : 76.f;
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self.collectionView registerNib:[UINib nibWithNibName:@"HomeProblemTopCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeProblemTopCollectCell"];
- UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- [self.collectionView setCollectionViewLayout:layout];
- [self.collectionView setContentOffset:CGPointZero animated:NO];
- self.topTitleL.text = model.Title;
- self.topContentL.attributedText = [[NSAttributedString alloc] initWithString:model.Blocks];
- [self.collectionView reloadData];
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
- {
- return 5.f;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
- {
- return 5.f;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return 1;
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- return CGSizeMake(101, 76);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString * imageStr = [self.dataArray objectAtIndex:indexPath.item];
- HomeProblemTopCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeProblemTopCollectCell" forIndexPath:indexPath];
- [cell setImageViewWithString:imageStr];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- WS(weakSelf);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
- });
- }
- @end
|