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.
89 lines
2.9 KiB
89 lines
2.9 KiB
4 years ago
|
//
|
||
|
// 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
|