小说绘上架版本
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// TFFiltrateCollectionView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFSortModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol TFFiltrateCollectionViewDelegate <NSObject>
|
||||
|
||||
- (void)selectFiltrateViewWithIndexPath:(NSIndexPath *)indexPath selectKeyword:(NSString *)keyword selectValue:(NSString *)value;
|
||||
|
||||
@end
|
||||
|
||||
@interface TFFiltrateCollectionView : UIView
|
||||
|
||||
@property (nonatomic ,strong) TFSearchBoxModel *searchModel;
|
||||
@property (nonatomic ,weak) id <TFFiltrateCollectionViewDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// TFFiltrateCollectionView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFFiltrateCollectionView.h"
|
||||
#import "TFFiltrateItemViewCell.h"
|
||||
|
||||
@interface TFFiltrateCollectionView ()<UICollectionViewDataSource, UICollectionViewDelegate>
|
||||
|
||||
@property (nonatomic ,strong) UICollectionViewFlowLayout *flowLayout;
|
||||
@property (nonatomic ,strong) UICollectionView *collectionView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFFiltrateCollectionView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
[self createSubViews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
[self addSubview:self.collectionView];
|
||||
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self);
|
||||
}];
|
||||
|
||||
|
||||
UIView *line = [[UIView alloc] init];
|
||||
line.backgroundColor = kGrayLineColor;
|
||||
[self addSubview:line];
|
||||
|
||||
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(kHalfMargin);
|
||||
make.bottom.equalTo(self.collectionView);
|
||||
make.width.mas_equalTo(self.mas_width);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
||||
{
|
||||
return self.searchModel.searchList.count;
|
||||
}
|
||||
|
||||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFOptionListModel *t_list = [self.searchModel.searchList objectOrNilAtIndex:indexPath.row];
|
||||
TFFiltrateItemViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TFFiltrateItemViewCell" forIndexPath:indexPath];
|
||||
cell.optionModel = t_list;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFOptionListModel *t_list = [self.searchModel.searchList objectOrNilAtIndex:indexPath.row];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(selectFiltrateViewWithIndexPath:selectKeyword:selectValue:)]) {
|
||||
[self.delegate selectFiltrateViewWithIndexPath:indexPath selectKeyword:self.searchModel.field selectValue:t_list.value];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSearchModel:(TFSearchBoxModel *)searchModel
|
||||
{
|
||||
#if !TF_Free_Mode
|
||||
NSMutableArray *t_array = [searchModel.searchList mutableCopy];
|
||||
for (TFOptionListModel *t_model in t_array) {
|
||||
if ([t_model.display isEqualToString:TFLocalizedString(@"免费")]) {
|
||||
[t_array removeObject:t_model];
|
||||
break;
|
||||
}
|
||||
}
|
||||
searchModel.searchList = [t_array copy];
|
||||
|
||||
#elif !TF_Super_Member_Mode
|
||||
NSMutableArray *t_array = [searchModel.searchList mutableCopy];
|
||||
for (TFOptionListModel *t_model in t_array) {
|
||||
if ([t_model.display isEqualToString:TFLocalizedString(@"会员")]) {
|
||||
[t_array removeObject:t_model];
|
||||
break;
|
||||
}
|
||||
}
|
||||
searchModel.searchList = [t_array copy];
|
||||
#endif
|
||||
|
||||
_searchModel = searchModel;
|
||||
|
||||
[self.collectionView reloadData];
|
||||
}
|
||||
|
||||
- (UICollectionView *)collectionView
|
||||
{
|
||||
if (!_collectionView) {
|
||||
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
|
||||
_collectionView.userInteractionEnabled = YES;
|
||||
_collectionView.backgroundColor = [UIColor clearColor];
|
||||
_collectionView.showsVerticalScrollIndicator = NO;
|
||||
_collectionView.showsHorizontalScrollIndicator = NO;
|
||||
_collectionView.alwaysBounceHorizontal = YES;
|
||||
_collectionView.delegate = self;
|
||||
_collectionView.dataSource = self;
|
||||
[_collectionView registerClass:[TFFiltrateItemViewCell class] forCellWithReuseIdentifier:@"TFFiltrateItemViewCell"];
|
||||
|
||||
if (@available(iOS 11.0, *)) {
|
||||
_collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
}
|
||||
}
|
||||
return _collectionView;
|
||||
}
|
||||
|
||||
- (UICollectionViewFlowLayout *)flowLayout
|
||||
{
|
||||
if (!_flowLayout) {
|
||||
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
|
||||
_flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
||||
_flowLayout.estimatedItemSize = CGSizeMake(30, 30);
|
||||
_flowLayout.minimumLineSpacing = kQuarterMargin;
|
||||
_flowLayout.sectionInset = UIEdgeInsetsMake(0, kQuarterMargin, 0, kQuarterMargin);
|
||||
}
|
||||
return _flowLayout;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TFFiltrateItemViewCell.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFSortModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFFiltrateItemViewCell : UICollectionViewCell
|
||||
|
||||
@property (nonatomic ,strong) TFOptionListModel *optionModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// TFFiltrateItemViewCell.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFFiltrateItemViewCell.h"
|
||||
|
||||
@interface TFFiltrateItemViewCell ()
|
||||
|
||||
@property (nonatomic ,strong) UILabel *titleLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFFiltrateItemViewCell
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
|
||||
self.titleLabel = [[UILabel alloc] init];
|
||||
self.titleLabel.backgroundColor = [UIColor whiteColor];
|
||||
self.titleLabel.textColor = kBlackColor;
|
||||
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.titleLabel.font = kFont12;
|
||||
self.titleLabel.userInteractionEnabled = YES;
|
||||
self.titleLabel.numberOfLines = 1;
|
||||
self.titleLabel.layer.cornerRadius = 10;
|
||||
self.titleLabel.layer.borderWidth = 0.5;
|
||||
self.titleLabel.layer.borderColor = kWhiteColor.CGColor;
|
||||
self.titleLabel.clipsToBounds = YES;
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kQuarterMargin);
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kQuarterMargin);
|
||||
make.width.mas_equalTo(30);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kQuarterMargin);
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kQuarterMargin).priorityLow();
|
||||
}];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setOptionModel:(TFOptionListModel *)optionModel
|
||||
{
|
||||
_optionModel = optionModel;
|
||||
|
||||
self.titleLabel.text = optionModel.display ? : @"";
|
||||
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.titleLabel] + kHalfMargin);
|
||||
}];
|
||||
|
||||
if (optionModel.checked) {
|
||||
[self setSelectedState];
|
||||
} else {
|
||||
[self setNormalState];
|
||||
}
|
||||
}
|
||||
|
||||
- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
|
||||
{
|
||||
UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
|
||||
attributes.frame = CGRectMake(0, 0, [TFViewHelper getDynamicWidthWithLabel:self.titleLabel] + kHalfMargin, self.height);
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
- (void)setSelectedState
|
||||
{
|
||||
self.titleLabel.textColor = kMainColor;
|
||||
self.titleLabel.backgroundColor = [UIColor whiteColor];
|
||||
self.titleLabel.layer.borderColor = kMainColor.CGColor;
|
||||
self.titleLabel.layer.borderWidth = 0.5;
|
||||
}
|
||||
|
||||
- (void)setNormalState
|
||||
{
|
||||
self.titleLabel.textColor = kBlackColor;
|
||||
self.titleLabel.backgroundColor = [UIColor whiteColor];
|
||||
self.titleLabel.layer.borderColor = [UIColor whiteColor].CGColor;
|
||||
self.titleLabel.layer.borderWidth = 0.5;
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// TFFiltrateView.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFSortModel.h"
|
||||
#import "TFFiltrateCollectionView.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^TFFiltrateViewSelectBlock)(NSString *keyword, NSString *value);
|
||||
@interface TFFiltrateView : UIView
|
||||
|
||||
@property (nonatomic ,strong) NSArray <TFSearchBoxModel *>*search_box;
|
||||
|
||||
@property (nonatomic ,copy) TFFiltrateViewSelectBlock selectBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// TFFiltrateView.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/25.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFFiltrateView.h"
|
||||
|
||||
#define SearchBarHeight 40
|
||||
|
||||
@interface TFFiltrateView ()<TFFiltrateCollectionViewDelegate>
|
||||
|
||||
@property (nonatomic ,strong) NSMutableArray *filtrateViewArray;
|
||||
@end
|
||||
|
||||
@implementation TFFiltrateView
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)selectFiltrateViewWithIndexPath:(NSIndexPath *)indexPath selectKeyword:(NSString *)keyword selectValue:(NSString *)value
|
||||
{
|
||||
if (self.selectBlock) {
|
||||
self.selectBlock(keyword, value);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSearch_box:(NSArray<TFSearchBoxModel *> *)search_box
|
||||
{
|
||||
_search_box = search_box;
|
||||
|
||||
if (!self.filtrateViewArray) {
|
||||
self.filtrateViewArray = [NSMutableArray array];
|
||||
|
||||
for (NSInteger i = 0; i < self.search_box.count; i ++) {
|
||||
|
||||
TFFiltrateCollectionView *filtrateCollectionView = [[TFFiltrateCollectionView alloc] initWithFrame:CGRectMake(0, SearchBarHeight * i, SCREEN_WIDTH, SearchBarHeight)];
|
||||
filtrateCollectionView.searchModel = [search_box objectOrNilAtIndex:i];
|
||||
filtrateCollectionView.delegate = self;
|
||||
|
||||
[self addSubview:filtrateCollectionView];
|
||||
[self.filtrateViewArray addObject:filtrateCollectionView];
|
||||
}
|
||||
} else {
|
||||
for (NSInteger i = 0; i < self.filtrateViewArray.count; i++) {
|
||||
TFFiltrateCollectionView *filtrateCollectionView = [self.filtrateViewArray objectOrNilAtIndex:i];
|
||||
filtrateCollectionView.searchModel = [search_box objectOrNilAtIndex:i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user