You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
5.8 KiB

//
// TFBookStoreComicBasicViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFBookStoreComicBasicViewCell.h"
#import "TFBookStoreComicBasicItemCell.h"
#import "TFBookStoreComicNormalItemCell.h"
#import "TFBookStoreComicMiddleItemCell.h"
#import "TFBookStoreComicMaxItemCell.h"
@interface TFBookStoreComicBasicViewCell ()
@property (nonatomic ,strong) UIImageView *iconView;
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) TFButton *moreButton;
@end
@implementation TFBookStoreComicBasicViewCell
- (void)createSubviews
{
[super createSubviews];
[self setupSubview];
[self setupSubviewFrame];
}
- (void)setupSubview
{
self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comic_label_hold"]];
self.iconView.hidden = YES;
[self.contentView addSubview:self.iconView];
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.moreButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"查看更多") buttonImageName:@"public_more" buttonIndicator:TFButtonIndicatorTitleLeft];
self.moreButton.buttonTintColor = kGrayTextLightColor;
self.moreButton.graphicDistance = 5;
self.moreButton.buttonImageScale = 0.35;
self.moreButton.hidden = YES;
[self.moreButton addTarget:self action:@selector(moreButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.moreButton];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.minimumInteritemSpacing = Comic_Cell_Line_Space;
flowLayout.minimumLineSpacing = 0.01;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.itemSize = CGSizeMake(Comic_NormalVertical_Width, Comic_NormalVertical_Height);
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;
[self.contentView addSubview:self.collectionView];
}
- (void)setupSubviewFrame
{
[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
make.width.mas_equalTo(kHalfMargin + kHalfMargin);
make.height.mas_equalTo(kHalfMargin + kHalfMargin);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin + kHalfMargin + kQuarterMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(kLabelHeight + kHalfMargin);
}];
[self.moreButton 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.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();
}];
}
- (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]);
}];
self.iconView.hidden = NO;
[self.collectionView reloadData];
switch (labelModel.style) {
case 1: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(labelModel.list.count < 3 ? Comic_MiddleCell_Height : Comic_MiddleCell_Height *2);
}];
}
break;
case 2: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(labelModel.list.count <= 3 ? Comic_NormalCell_Height : Comic_NormalCell_Height *2);
}];
}
break;
case 3: {
[self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(Comic_MaxCell_Height + (labelModel.list.count == 1 ? 0 : Comic_NormalCell_Height));
}];
}
break;
default:
break;
}
}
}
- (void)setShowTopMoreButton:(BOOL)showTopMoreButton
{
_showTopMoreButton = showTopMoreButton;
self.moreButton.hidden = !showTopMoreButton;
}
- (void)moreButtonClick
{
if (self.cellSelectMoreBlock) {
self.cellSelectMoreBlock(self.labelModel);
}
}
@end