小说绘上架版本

This commit is contained in:
xtfei2011
2021-02-07 11:24:08 +08:00
commit ee5c1c8b12
1762 changed files with 115892 additions and 0 deletions
@@ -0,0 +1,24 @@
//
// TFBookStoreNovelController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreNovelController : TFBasicViewController
@property (nonatomic ,assign) CGFloat channel;
@property (nonatomic ,assign) CGFloat scrollViewContentOffsetY;
@property (nonatomic ,strong) NSArray *hotwordArray;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,400 @@
//
// TFBookStoreNovelController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelController.h"
#import "TFLimitFreeViewController.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFBookStoreMenuView.h"
#import "TFBookStoreLabelModel.h"
#import "TFBannerActionManager.h"
// 分类
#import "TFSortViewController.h"
// 排行榜
#import "TFPopularityViewController.h"
// 包月
#import "TFMemberViewController.h"
// 完结
#import "TFCompleteViewController.h"
// 限免
#import "TFFreeViewController.h"
#import "TFWebViewController.h"
@interface TFBookStoreNovelController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) TFBookStoreModel *bookStoreNovelModel;
@property (nonatomic ,strong) TFBookStoreMenuView *headerView;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFBookStoreNovelController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Restore_Network object:nil];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
self.hotwordArray = [NSArray array];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Channel_Change object:nil];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
WS(weakSelf)
self.headerView = [[TFBookStoreMenuView alloc] init];
self.headerView.productionType = self.productionType;
self.headerView.bannerrImageClickBlock = ^(TFBannerModel * _Nonnull bannerModel) {
if ([TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel]) {
[weakSelf.navigationController pushViewController:[TFBannerActionManager getBannerActionWithBannerModel:bannerModel productionType:TFProductionTypeNovel] animated:YES];
}
};
self.headerView.menuButtonClickBlock = ^(TFMenuButtonType menuButtonType, NSString * _Nonnull menuButtonTitle) {
switch (menuButtonType) {
case TFMenuButtonTypeFree: {
TFFreeViewController *free = [[TFFreeViewController alloc] init];
free.productionType = weakSelf.productionType;
free.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:free animated:YES];
}
break;
case TFMenuButtonTypeComplete: {
TFCompleteViewController *complete = [[TFCompleteViewController alloc] init];
complete.productionType = weakSelf.productionType;
complete.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:complete animated:YES];
}
break;
case TFMenuButtonTypeSort: {
TFSortViewController *sort = [[TFSortViewController alloc] init];
sort.productionType = weakSelf.productionType;
sort.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:sort animated:YES];
}
break;
case TFMenuButtonTypePopularity: {
TFPopularityViewController *popularity = [[TFPopularityViewController alloc] init];
popularity.productionType = weakSelf.productionType;
popularity.navTitle = menuButtonTitle;
[weakSelf.navigationController pushViewController:popularity animated:YES];
}
break;
case TFMenuButtonTypeMember: {
TFMemberViewController *member = [[TFMemberViewController alloc] init];
member.productionType = weakSelf.productionType;
[weakSelf.navigationController pushViewController:member animated:YES];
}
break;
default:
break;
}
};
self.mainTableViewGroup.tableHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH);
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.bookStoreNovelModel.label.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:indexPath.section];
if (labelModel.ad_type == 0) {
return [self createCellWithTabelView:tableView indexPath:indexPath labelModel:labelModel];
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
Class cellClass = TFBookStoreNovelStyleOneCell.class;
switch (labelModel.style) {
case 1:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
case 2:
cellClass = TFBookStoreNovelStyleTwoCell.class;
break;
case 3:
cellClass = TFBookStoreNovelStyleThreeCell.class;
break;
case 4:
cellClass = TFBookStoreNovelStyleFourCell.class;
break;
default:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
}
WS(weakSelf)
TFBookStoreNovelBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
if (!cell) {
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *novelDetail = [[TFNovelDetailViewController alloc] init];
novelDetail.book_id = production_id;
[weakSelf.navigationController pushViewController:novelDetail animated:YES];
};
return cell;
}
- (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:labelModel refresh:self.needRefresh];
cell.mainTableView = tableView;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (labelModel.ad_type != 0) {
return kHalfMargin;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (labelModel.can_more || labelModel.can_refresh) {
if (section == self.bookStoreNovelModel.label.count - 1) {
return 40;
}
return 30;
}
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
view.backgroundColor = [UIColor whiteColor];
CGFloat buttonX = SCREEN_WIDTH / 4;
CGFloat buttonW = SCREEN_WIDTH / 2;
CGFloat buttonH = 30;
TFBookStoreLabelModel *labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:section];
if (!labelModel.can_more && !labelModel.can_refresh) {
return view;
}
if (labelModel.style == 5) { // 排行榜
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH - 2 * kMargin, buttonH) btnTitle:TFLocalizedString(@"查看更多排行榜") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(rankButtonClick:)];
moreButton.graphicDistance = 5;
moreButton.tag = section;
[view addSubview:moreButton];
return view;
}
TFButton *moreButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, buttonW, buttonH) btnTitle:TFLocalizedString(@"更多") btnImageName:@"comic_mall_more" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(moreButtonClick:)];
moreButton.graphicDistance = 5;
moreButton.tag = section;
TFButton *changeButton = [TFButton initWithFrame:CGRectMake(buttonX, 0, buttonW, buttonH) btnTitle:TFLocalizedString(@"换一换") btnImageName:@"comic_mall_refresh" backgroundColor:kGrayViewColor btnTintColor:kGrayTextLightColor btnStyle:TFButtonIndicatorTitleLeft cornerRadius:15 target:self action:@selector(changeButtonClick:)];
changeButton.graphicDistance = 5;
changeButton.buttonImageScale = 0.5;
changeButton.tag = section;
if (labelModel.can_more && !labelModel.can_refresh) {
[view addSubview:moreButton];
}
if (!labelModel.can_more && labelModel.can_refresh) {
[view addSubview:changeButton];
}
if (labelModel.can_more && labelModel.can_refresh) {
moreButton.frame = CGRectMake(kMargin, 0, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
changeButton.frame = CGRectMake(2 * kMargin + (SCREEN_WIDTH - 3 * kMargin) / 2, 0, (SCREEN_WIDTH - 3 * kMargin) / 2, buttonH);
[view addSubview:moreButton];
[view addSubview:changeButton];
}
return view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
CGFloat pointY = scrollView.contentOffset.y;
self.scrollViewContentOffsetY = pointY;
}
#pragma mark - 点击事件
- (void)moreButtonClick:(UIButton *)sender
{
TFBookStoreLabelModel *t_labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:sender.tag];
if (t_labelModel.expire_time > 0) {
TFLimitFreeViewController *vc = [[TFLimitFreeViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
} else {
TFBookStoreMoreViewController *vc = [[TFBookStoreMoreViewController alloc] init];
vc.productionType = self.productionType;
vc.recommend_id = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)changeButtonClick:(TFButton *)sender
{
[sender startSpin];
[self changeBookRecommendRequestAtIndex:sender.tag complete:^{
[sender stopSpin];
}];
}
- (void)rankButtonClick:(UIButton *)sender
{
TFPopularityViewController *vc = [[TFPopularityViewController alloc] init];
vc.productionType = self.productionType;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)netRequest
{
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"channel_id"] = self.channel != 0 ? [TFUtilsHelper formatStringWithInteger:self.channel] : @(TFSystemInfoManager.sexChannel);
[TFNetworkTools POSTQuick:Book_Mall_Center parameters:params model:TFBookStoreModel.class success:^(BOOL isSuccess, TFBookStoreModel * _Nullable t_model, BOOL isCache, TFNetworkRequestModel * _Nonnull requestModel) {
if (weakSelf.bookStoreNovelModel && isCache) return;
if (isSuccess) {
weakSelf.bookStoreNovelModel = t_model;
weakSelf.headerView.mallCenterModel = t_model;
weakSelf.hotwordArray = t_model.hot_word;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reload_Mall_Hot_Word object:nil];
}
[weakSelf.mainTableViewGroup endRefreshing];
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableViewGroup endRefreshing];
[weakSelf.mainTableViewGroup reloadData];
}];
}
- (void)changeBookRecommendRequestAtIndex:(NSInteger)index complete:(void(^)(void))complete
{
TFBookStoreLabelModel *t_labelModel = [self.bookStoreNovelModel.label objectOrNilAtIndex:index];
if (t_labelModel.recommend_id <= 0) {
return;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"recommend_id"] = [TFUtilsHelper formatStringWithInteger:t_labelModel.recommend_id];
[TFNetworkTools POST:Book_Refresh parameters:params model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[weakSelf.bookStoreNovelModel.label objectAtIndex:index].list = t_model.list;
TFBookStoreNovelBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index]];
t_model.style = cell.labelModel.style;
cell.labelModel = t_model;
!complete ?: complete();
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
!complete ?: complete();
}];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@@ -0,0 +1,33 @@
//
// TFBookStoreNovelBasicItemCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreNovelBasicItemCell : UICollectionViewCell
@property (nonatomic ,strong) TFProductionCoverView *coverView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *subtitleLabel;
@property (nonatomic ,strong) UIView *lineView;
@property (nonatomic ,strong) TFProductionModel *labelListModel;
@property (nonatomic ,strong) NSIndexPath *cellIndexPath;
@property (nonatomic ,assign) BOOL hiddenEndLine;
- (void)createSubviews;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,109 @@
//
// TFBookStoreNovelBasicItemCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelBasicItemCell.h"
@implementation TFBookStoreNovelBasicItemCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = kWhiteColor;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
// 封面
self.coverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
self.coverView.userInteractionEnabled = YES;
[self addSubview:self.coverView];
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(kHalfMargin);
make.width.mas_equalTo(BOOK_WIDTH - 10);
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH - 10, 3, 4));
make.bottom.mas_equalTo(self.mas_bottom).priorityLow();
}];
// 书名
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.numberOfLines = 1;
self.titleLabel.backgroundColor = kWhiteColor;
self.titleLabel.font = kMainFont;
self.titleLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.coverView.mas_top);
make.right.mas_equalTo(self.mas_right);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
// 子标题
self.subtitleLabel = [[UILabel alloc] init];
self.subtitleLabel.textColor = kGrayTextColor;
self.subtitleLabel.textAlignment = NSTextAlignmentLeft;
self.subtitleLabel.font = kFont11;
self.subtitleLabel.numberOfLines = 1;
self.subtitleLabel.hidden = YES;
[self addSubview:self.subtitleLabel];
[self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.top.mas_equalTo(self.titleLabel.mas_bottom);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.height.mas_equalTo(self.titleLabel.mas_height);
make.bottom.mas_equalTo(self.mas_bottom).priorityLow();
}];
// 横线
self.lineView = [[UIView alloc] init];
self.lineView.hidden = YES;
self.lineView.backgroundColor = kGrayLineColor;
[self addSubview:self.lineView];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(self.mas_bottom).with.offset(-kCellLineHeight);
make.right.mas_equalTo(self.mas_right).with.offset(kHalfMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
_labelListModel = labelListModel;
if (!labelListModel) {
return;
}
self.coverView.coverImageUrl = labelListModel.cover;
self.coverView.productionType = labelListModel.productionType;
self.titleLabel.text = labelListModel.name ? : @"";
}
- (void)setHiddenEndLine:(BOOL)hiddenEndLine
{
_hiddenEndLine = hiddenEndLine;
self.lineView.hidden = hiddenEndLine;
}
- (void)setCellIndexPath:(NSIndexPath *)cellIndexPath
{
_cellIndexPath = cellIndexPath;
}
@end
@@ -0,0 +1,34 @@
//
// TFBookStoreNovelBasicViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreLabelModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFBookStoreNovelBasicViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UICollectionView *collectionView;
// 默认 NO 与showTopRefreshButton 互斥
@property (nonatomic ,assign) BOOL showTopMoreBtn;
// 默认 NO 与showTopMoreButton 互斥
@property (nonatomic ,assign) BOOL showTopRefreshBtn;
@property (nonatomic ,strong) TFBookStoreLabelModel *labelModel;
@property (nonatomic ,copy) void (^cellDidSelectItemBlock)(NSInteger production_id);
@property (nonatomic ,copy) void (^cellSelectMoreBlock)(TFBookStoreLabelModel *labelModel);
@property (nonatomic ,copy) void (^cellSelectRefreshBlock)(TFBookStoreLabelModel *labelModel, NSIndexPath *indexPath);
// 停止刷新状态
- (void)stopRefreshing;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,242 @@
//
// 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
@@ -0,0 +1,32 @@
//
// TFBookStoreNovelHorizontalCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横排布书籍cell
┌──────────────┐ ┌────────────────────────┐
│ │ │ book Name │
│ │ └────────────────────────┘
│ │ ┌────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └────────────────────────┘
*/
#define HorizontalCellHeight (kGeometricHeight(BOOK_WIDTH - 10, 3, 4) + kHalfMargin)
@interface TFBookStoreNovelHorizontalCell : TFBookStoreNovelBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,118 @@
//
// TFBookStoreNovelHorizontalCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelHorizontalCell.h"
#import "TFTagboardView.h"
@interface TFBookStoreNovelHorizontalCell ()
@property (nonatomic ,strong) UILabel *authorLabel;
@property (nonatomic ,strong) TFTagboardView *tagboardView;
@property (nonatomic ,strong) YYLabel *introductionLabel;
@end
@implementation TFBookStoreNovelHorizontalCell
- (void)createSubviews
{
[super createSubviews];
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
// 作者
self.authorLabel = [[UILabel alloc] init];
self.authorLabel.numberOfLines = 1;
self.authorLabel.backgroundColor = kWhiteColor;
self.authorLabel.font = kFont11;
self.authorLabel.textColor = kColorRGBA(176, 176, 177, 1);
self.authorLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.authorLabel];
// 标签
self.tagboardView = [[TFTagboardView alloc] init];
self.tagboardView.font = kFont11;
self.tagboardView.textAlignment = TFTagboardTextAlignmentRight;
self.tagboardView.borderStyle = TFTagboardBorderStyleBorder;
self.tagboardView.cornerRadius = 3;
self.tagboardView.spacing = 10;
[self addSubview:self.tagboardView];
// 简介
self.introductionLabel = [[YYLabel alloc] init];
self.introductionLabel.numberOfLines = 3;
self.introductionLabel.textVerticalAlignment = YYTextVerticalAlignmentTop;
self.introductionLabel.backgroundColor = kWhiteColor;
self.introductionLabel.font = kFont13;
self.introductionLabel.textColor = kColorRGBA(102, 102, 102, 1);
self.introductionLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:self.introductionLabel];
}
- (void)setupSubviewFrame
{
[self.coverView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(BOOK_WIDTH - 10);
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH - 10, 3, 4));
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.coverView.mas_top);
make.right.mas_equalTo(self.mas_right);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
[self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.bottom.mas_equalTo(self.coverView.mas_bottom);
make.width.mas_equalTo(10);
make.height.mas_equalTo(self.titleLabel.mas_height);
}];
[self.tagboardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.authorLabel.mas_right).with.offset(kHalfMargin);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.centerY.mas_equalTo(self.authorLabel.mas_centerY);
make.height.mas_equalTo(self.authorLabel.mas_height);
}];
[self.introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.right.mas_equalTo(self.titleLabel.mas_right);
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kHalfMargin);
make.bottom.mas_equalTo(self.authorLabel.mas_top).with.offset(- kHalfMargin);
}];
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
[super setLabelListModel:labelListModel];
self.authorLabel.text = labelListModel.author ? : @"";
[self.authorLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.authorLabel]);
}];
self.tagboardView.tagboardArray = labelListModel.tag;
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: labelListModel.production_descirption ? : @""];
text.lineSpacing = 5;
text.font = kFont13;
text.color = kColorRGBA(118, 118, 118, 1);
self.introductionLabel.attributedText = text;
}
@end
@@ -0,0 +1,43 @@
//
// TFBookStoreNovelStyleFourCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横一竖三排布方式
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleFourCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,82 @@
//
// TFBookStoreNovelStyleFourCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
@implementation TFBookStoreNovelStyleFourCell
static NSString *verticalCell = @"TFBookStoreNovelVerticalCell";
static NSString *horizontalCell = @"TFBookStoreNovelHorizontalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:verticalCell];
[self.collectionView registerClass:[TFBookStoreNovelHorizontalCell class] forCellWithReuseIdentifier:horizontalCell];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
if (self.labelModel.list.count <= 1) {
return 1;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.labelModel.list.count <= 1) {
return 1;
}
if (section == 0) {
return 1;
} else {
return self.labelModel.list.count > 3?3:self.labelModel.list.count - 1;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = YES;
return cell;
} else {
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 1];
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight);
}
return CGSizeMake(BOOK_WIDTH, VerticalCellHeight);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section + indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,35 @@
//
// TFBookStoreNovelStyleOneCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
一排三列 排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleOneCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,50 @@
//
// TFBookStoreNovelStyleOneCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelStyleOneCell
static NSString *cellID = @"TFBookStoreNovelVerticalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (!self.labelModel.list) {
return 3;
}
return self.labelModel.list.count <= 3 ? self.labelModel.list.count : 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,61 @@
//
// TFBookStoreNovelStyleThreeCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
横三竖三排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
┌──────────────┐ ┌──────────────────────────────────┐
│ │ │ book Name │
│ │ └──────────────────────────────────┘
│ │ ┌──────────────────────────────────┐
│ photo │ │ │
│ │ │ describe │
│ │ │ │
│ │ │ │
└──────────────┘ └──────────────────────────────────┘
*/
@interface TFBookStoreNovelStyleThreeCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,96 @@
//
// TFBookStoreNovelStyleThreeCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelVerticalCell.h"
#import "TFBookStoreNovelHorizontalCell.h"
@implementation TFBookStoreNovelStyleThreeCell
static NSString *verticalCell = @"TFBookStoreNovelVerticalCell";
static NSString *horizontalCell = @"TFBookStoreNovelHorizontalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:verticalCell];
[self.collectionView registerClass:[TFBookStoreNovelHorizontalCell class] forCellWithReuseIdentifier:horizontalCell];
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
if (self.labelModel.list.count <= 3) {
return 1;
}
return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (self.labelModel.list.count <= 3) {
return self.labelModel.list.count;
}
if (section == 0) {
return 3;
}
return self.labelModel.list.count - 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:verticalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
} else {
TFBookStoreNovelHorizontalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:horizontalCell forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row + 3];
cell.hiddenEndLine = indexPath.row == self.labelModel.list.count - 3 - 1;
return cell;
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(BOOK_WIDTH, VerticalCellHeight);
}
return CGSizeMake(SCREEN_WIDTH - kMargin, HorizontalCellHeight);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if (section == 0) {
return UIEdgeInsetsMake(0, kHalfMargin, 0, kHalfMargin);
}
return UIEdgeInsetsMake(kHalfMargin, kHalfMargin, 0, kHalfMargin);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return kHalfMargin;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.section * 3 + indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(labelListModel.production_id);
}
}
@end
@@ -0,0 +1,46 @@
//
// TFBookStoreNovelStyleTwoCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicViewCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
两排三列排布方式
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
│ photo │ │ photo │ │ photo │
│ │ │ │ │ │
│ │ │ │ │ │
│ │ │ │ │ │
└──────────────┘ └──────────────┘ └──────────────┘
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ book Name │ │ book Name │ │ book Name │
└──────────────┘ └──────────────┘ └──────────────┘
*/
@interface TFBookStoreNovelStyleTwoCell : TFBookStoreNovelBasicViewCell <UICollectionViewDelegate, UICollectionViewDataSource>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,53 @@
//
// TFBookStoreNovelStyleTwoCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelStyleTwoCell
static NSString *cellID = @"TFBookStoreNovelVerticalCell";
- (void)createSubviews
{
[super createSubviews];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass:[TFBookStoreNovelVerticalCell class] forCellWithReuseIdentifier:cellID];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.labelModel.list.count <= 6 ? self.labelModel.list.count : 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreNovelVerticalCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.labelListModel = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
return cell;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return kHalfMargin;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *production = [self.labelModel.list objectOrNilAtIndex:indexPath.row];
if (self.cellDidSelectItemBlock) {
self.cellDidSelectItemBlock(production.production_id);
}
}
@end
@@ -0,0 +1,36 @@
//
// TFBookStoreNovelVerticalCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBookStoreNovelBasicItemCell.h"
NS_ASSUME_NONNULL_BEGIN
/*
竖直排布书籍cell
┌──────────────┐
│ │
│ │
│ │
│ photo │
│ │
│ │
│ │
└──────────────┘
┌──────────────┐
│ book Name │
└──────────────┘
*/
#define VerticalCellHeight (BOOK_HEIGHT + BOOK_CELL_TITLE_HEIGHT + kQuarterMargin)
@interface TFBookStoreNovelVerticalCell : TFBookStoreNovelBasicItemCell
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,51 @@
//
// TFBookStoreNovelVerticalCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreNovelVerticalCell.h"
@implementation TFBookStoreNovelVerticalCell
- (void)createSubviews
{
[super createSubviews];
[self.coverView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.coverView.mas_left);
make.top.mas_equalTo(self.coverView.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(self.coverView.mas_width);
make.height.mas_equalTo(BOOK_CELL_TITLE_HEIGHT / 2);
}];
self.subtitleLabel.hidden = NO;
}
- (void)setLabelListModel:(TFProductionModel *)labelListModel
{
[super setLabelListModel:labelListModel];
NSString *str = @"";
for (TFTagModel *tagModel in labelListModel.tag) {
if (tagModel.tab.length > 0) {
str = [[str stringByAppendingString:tagModel.tab ? : @""] stringByAppendingString:@" "];
}
}
if (str.length == 0) {
str = labelListModel.production_descirption;
}
self.subtitleLabel.text = str;
}
@end