// // TFBookStoreNovelBasicViewCell.m // TFReader // // Created by 谢腾飞 on 2020/12/16. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFBookStoreNovelBasicViewCell.h" #import "TFBookStoreNovelHorizontalCell.h" #import "TFBookStoreNovelVerticalCell.h" #import "WXYZ_CountDownView.h" @interface TFBookStoreNovelBasicViewCell () @property (nonatomic ,strong) UIImageView *iconView; @property (nonatomic ,strong) WXYZ_CountDownView *countdownView; @property (nonatomic ,strong) TFButton *moreBtn; @property (nonatomic ,strong) TFButton *refreshBtn; @end @implementation TFBookStoreNovelBasicViewCell - (void)createSubviews { [super createSubviews]; [self setupSubview]; [self setupSubviewFrame]; } - (void)setupSubview { self.titleLabel = [[UILabel alloc] init]; self.titleLabel.textAlignment = NSTextAlignmentLeft; self.titleLabel.textColor = kBlackColor; self.titleLabel.backgroundColor = kGrayViewColor; self.titleLabel.font = kBoldFont16; [self.contentView addSubview:self.titleLabel]; self.moreBtn = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"查看更多") buttonImageName:@"public_more" buttonIndicator:TFButtonIndicatorTitleLeft]; self.moreBtn.buttonTintColor = kGrayTextLightColor; self.moreBtn.graphicDistance = 5; self.moreBtn.buttonImageScale = 0.35; self.moreBtn.hidden = YES; [self.moreBtn addTarget:self action:@selector(moreButtonClick) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:self.moreBtn]; self.refreshBtn = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"换一换") buttonImageName:@"comic_mall_refresh" buttonIndicator:TFButtonIndicatorTitleLeft]; self.refreshBtn.buttonTintColor = kGrayTextLightColor; self.refreshBtn.graphicDistance = 5; self.refreshBtn.buttonImageScale = 0.5; self.refreshBtn.hidden = YES; [self.refreshBtn addTarget:self action:@selector(refreshButtonClick) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:self.refreshBtn]; self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]]; self.iconView.hidden = YES; [self.contentView addSubview:self.iconView]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.minimumLineSpacing = 0; flowLayout.minimumInteritemSpacing = 0; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.itemSize = CGSizeMake(BOOK_WIDTH , VerticalCellHeight); flowLayout.sectionInset = UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin); self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; self.collectionView.scrollEnabled = NO; self.collectionView.backgroundColor = [UIColor clearColor]; self.collectionView.alwaysBounceVertical = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; if (@available(iOS 11.0, *)) { self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } [self.contentView addSubview:self.collectionView]; // 倒计时 self.countdownView = [[WXYZ_CountDownView alloc] init]; self.countdownView.hidden = YES; [self.contentView addSubview:self.countdownView]; } - (void)setupSubviewFrame { [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(kMargin + kHalfMargin); make.top.mas_equalTo(self.contentView.mas_top); make.width.mas_equalTo(100); make.height.mas_equalTo(kLabelHeight + kHalfMargin); }]; [self.moreBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); make.width.mas_equalTo(80); make.height.mas_equalTo(30); }]; [self.refreshBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); make.width.mas_equalTo(80); make.height.mas_equalTo(30); }]; [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(kHalfMargin); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); make.width.mas_equalTo(kHalfMargin + kQuarterMargin); make.height.mas_equalTo(kHalfMargin + kQuarterMargin); }]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(self.titleLabel.mas_bottom); make.width.mas_equalTo(self.contentView.mas_width); make.height.mas_equalTo(SCREEN_WIDTH); make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow(); }]; [self.countdownView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.titleLabel.mas_right).with.offset(kHalfMargin); make.centerY.mas_equalTo(self.titleLabel.mas_centerY); make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin); make.height.mas_equalTo(20); }]; } - (void)setLabelModel:(TFBookStoreLabelModel *)labelModel { if (labelModel && _labelModel != labelModel) { _labelModel = labelModel; if (labelModel.label.length > 0) { self.titleLabel.text = labelModel.label; } self.titleLabel.backgroundColor = kWhiteColor; [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.titleLabel]); }]; if (labelModel.expire_time > 0) { self.countdownView.hidden = NO; self.countdownView.timeStamp = labelModel.expire_time; } else if (labelModel.expire_time == -1) { self.countdownView.hidden = YES; self.countdownView.timeStamp = 0; } else { self.countdownView.hidden = YES; } self.iconView.hidden = NO; [self.collectionView reloadData]; switch (labelModel.style) { case 1: { // TFBookStoreNovelStyleOneCell [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(VerticalCellHeight + kHalfMargin); }]; } break; case 2: { // TFBookStoreNovelStyleTwoCell [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.labelModel.list.count <= 3 ? (VerticalCellHeight + kHalfMargin) : ((VerticalCellHeight + kHalfMargin) *2)); }]; } break; case 3: { // TFBookStoreNovelStyleThreeCell [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.labelModel.list.count <= 3 ? (VerticalCellHeight + kHalfMargin) : VerticalCellHeight + (HorizontalCellHeight + kHalfMargin) * ((self.labelModel.list.count - 3) <= 3 ? (self.labelModel.list.count - 3) : 3)); }]; } break; case 4: { // TFBookStoreNovelStyleFourCell [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(self.labelModel.list.count <= 1 ? HorizontalCellHeight : VerticalCellHeight + HorizontalCellHeight + kHalfMargin); }]; } break; default: { [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(VerticalCellHeight + kHalfMargin); }]; } break; } } // self.refreshBtn.hidden = (labelModel.list.count == 0); self.iconView.hidden = (labelModel.list.count == 0); self.titleLabel.hidden = (labelModel.list.count == 0); } - (void)setShowTopMoreBtn:(BOOL)showTopMoreBtn { _showTopMoreBtn = showTopMoreBtn; self.moreBtn.hidden = !showTopMoreBtn; self.refreshBtn.hidden = showTopMoreBtn; } - (void)setShowTopRefreshBtn:(BOOL)showTopRefreshBtn { _showTopRefreshBtn = showTopRefreshBtn; self.refreshBtn.hidden = !showTopRefreshBtn; self.moreBtn.hidden = showTopRefreshBtn; } - (void)stopRefreshing { [self.refreshBtn stopSpin]; } - (void)moreButtonClick { if (self.cellSelectMoreBlock) { self.cellSelectMoreBlock(self.labelModel); } } - (void)refreshButtonClick { [self.refreshBtn startSpin]; if (self.cellSelectRefreshBlock) { self.cellSelectRefreshBlock(self.labelModel, self.index); } else { [self.refreshBtn stopSpin]; } } @end