123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- //
- // HomeWeiCousreCell.m
- // smartRhino
- //
- // Created by niuzhen on 2020/5/16.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeWeiCousreCell.h"
- #import "HomeWeiCousreCollectCell.h"
- #import "BookAlertModel.h"
- #import "NSDate+Extension.h"
- @implementation HomeWeiCousreCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.imgV.layer.cornerRadius = 2.5f;
- self.imgV.layer.masksToBounds = YES;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- + (HomeWeiCousreCell *)configCell0:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeWeiCousreCell0";
- HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:0];
- }
- return cell;
- }
- + (HomeWeiCousreCell *)configCell1:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeWeiCousreCell1";
- HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:1];
- }
- return cell;
- }
- + (HomeWeiCousreCell *)configCell2:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeWeiCousreCell2";
- HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:2];
- }
- return cell;
- }
- + (HomeWeiCousreCell *)configCell3:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeWeiCousreCell3";
- HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:3];
- }
- return cell;
- }
- + (HomeWeiCousreCell *)configCell4:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
- static NSString *cellIdentifer = @"HomeWeiCousreCell4";
- HomeWeiCousreCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeWeiCousreCell" owner:nil options:nil] objectAtIndex:4];
- }
- return cell;
- }
- - (void)setDataWithDetailModel:(BookListenModel *)model
- {
- self.timeL.text = [NSDate getTimeStringAutoShort2:model.AddDate];
- self.titleL.text = model.Title;
- self.nameL.text = model.Author;
- self.numL.text = [NSString stringWithFormat:@"%ld人已学习",model.ReadCount];
- }
- - (void)setDataWithSubModel:(BookListenSubModel *)model
- {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.VideoImage] placeholderImage:IMG(@"img_placeHolder")];
- self.titleL.text = model.Name;
- self.timeL.text = model.Duration;
- self.playTimeL.text = model.Duration;
- // self.subTitleL.text = model.SectionName;
- self.nameL.text = model.Author;
- // self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- }
- - (void)setDataWithRecommendModel:(BookRecommendModel *)model
- {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
- self.titleL.text = model.Title;
- CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
- if (height > 30) {
- self.subTitleL.numberOfLines = 1;
- }else{
- self.subTitleL.numberOfLines = 2;
- }
- self.timeL.text = [NSDate getTimeStringAutoShort3:model.CreatedDate];
- self.playTimeL.text = model.Duration;
- self.subTitleL.text = model.Summary;
- self.nameL.text = model.Author;
- self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- }
- - (void)setDataWithIndexModel:(HomeSubItemModel *)model searchText:(NSString *)text
- {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
- self.titleL.attributedText = [ZYCTool checkOfString:model.Title withSearchText:text withColor:UIColorHex(0xFF5252)];
- CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 205, MAXFLOAT)].height;
- if (height > 30) {
- self.subTitleL.numberOfLines = 1;
- }else{
- self.subTitleL.numberOfLines = 2;
- }
- self.subTitleL.text = model.Summary;
- self.nameL.text = model.Author;
- self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- }
- - (void)setDataWithModel:(HomeSubItemModel *)model
- {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
- self.titleL.text = model.Title;
- CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
- if (height > 30) {
- self.subTitleL.numberOfLines = 1;
- }else{
- self.subTitleL.numberOfLines = 2;
- }
- self.subTitleL.text = model.Summary;
- self.nameL.text = model.Author;
- self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- }
- - (void)setDataVideoModel:(BookChanelRightModel *)model
- {
- [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrls] placeholderImage:IMG(@"img_placeHolder")];
- self.titleL.text = model.Title;
- CGFloat height = [self.titleL sizeThatFits:CGSizeMake(SCREEN_WIDTH - 175, MAXFLOAT)].height;
- if (height > 30) {
- self.subTitleL.numberOfLines = 1;
- }else{
- self.subTitleL.numberOfLines = 2;
- }
- self.subTitleL.text = model.Summary;
- self.nameL.text = model.Author;
- self.playTimeL.text = model.Duration;
- self.numL.text = [NSString stringWithFormat:@"%ld",model.ReadCount];
- }
- - (void)setDataRightModel:(BookChanelRightModel *)model
- {
- self.titleL.text = model.Name;
- self.subTitleL.text = model.ExpandName;
- }
- - (void)setCollData
- {
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
- 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 setArray];
- [self.collectionView reloadData];
- }
- - (void)setCollDataArray:(NSArray *)array
- {
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- self.collectionView.showsVerticalScrollIndicator = NO;
- self.collectionView.showsHorizontalScrollIndicator = NO;
- [self.collectionView registerNib:[UINib nibWithNibName:@"HomeWeiCousreCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeWeiCousreCollectCell"];
- 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 setArray:array];
- [self.collectionView reloadData];
- NSInteger item = 0;
- for (NSInteger i = 0; i < array.count; i ++) {
- BookListenSubModel * model = array[i];
- if (model.isSelect) {
- item = i;
- }
- }
- WS(weakSelf);
- NSIndexPath * indexPath = [NSIndexPath indexPathForItem:item inSection:0];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
- });
- }
- - (void)setArray:(NSArray *)array
- {
- self.dataArray = array.modelCopy;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
- {
- return 15.f;
- }
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
- {
- return 15.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(135, 80);
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- HomeWeiCousreCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeWeiCousreCollectCell" forIndexPath:indexPath];
- BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.item];
- [cell setDataWithTitle:model.Name isSelect:model.isSelect];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- WS(weakSelf);
- [collectionView deselectItemAtIndexPath:indexPath animated:YES];
- BookListenSubModel * model = [self.dataArray objectAtIndex:indexPath.item];
- for (BookListenSubModel * smodel in self.dataArray) {
- smodel.isSelect = NO;
- }
- model.isSelect = YES;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [weakSelf.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
- });
- [self.collectionView reloadData];
- if (self.ClickItemBlock) {
- self.ClickItemBlock(model);
- }
- }
- @end
|