Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeRecommendTableViewCell.m
2022-03-04 19:54:17 +08:00

192 lines
6.2 KiB
Objective-C

//
// XPHomeRecommendTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/2/21.
// 最新推荐
#import "XPHomeRecommendTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
///View
#import "XPHomeRecommendListView.h"
@interface XPHomeRecommendTableViewCell ()
///第一个 大的
@property (nonatomic,strong) XPHomeRecommendListView *firstView;
///第二个 小的
@property (nonatomic,strong) XPHomeRecommendListView *secondView;
///第三个 小的
@property (nonatomic,strong) XPHomeRecommendListView *thirdView;
///第四个 小的
@property (nonatomic,strong) XPHomeRecommendListView *fourthView;
///第五个 小的
@property (nonatomic,strong) XPHomeRecommendListView *fiftView;
///第六个 小的
@property (nonatomic,strong) XPHomeRecommendListView *sixView;
@property (nonatomic,strong) NSArray<XPHomeRecommendListView *> *viewList;
@end
@implementation XPHomeRecommendTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.firstView];
[self.contentView addSubview:self.secondView];
[self.contentView addSubview:self.thirdView];
[self.contentView addSubview:self.fourthView];
[self.contentView addSubview:self.fiftView];
[self.contentView addSubview:self.sixView];
self.viewList = @[self.firstView, self.secondView, self.thirdView,self.fourthView, self.fiftView, self.sixView];
}
- (void)initSubViewConstraints {
CGFloat spaceWidth = 11 * kScreenScale;
[self.firstView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(226 * kScreenScale, 230 * kScreenScale));
make.left.mas_equalTo(self.contentView).offset(15);
make.top.mas_equalTo(self.contentView);
}];
[self.secondView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(108 * kScreenScale, 108 * kScreenScale));
make.left.mas_equalTo(self.firstView.mas_right).offset(spaceWidth);
make.top.mas_equalTo(self.contentView);
}];
[self.thirdView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.left.mas_equalTo(self.secondView);
make.top.mas_equalTo(self.secondView.mas_bottom).offset(spaceWidth);
}];
[self.fourthView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(self.secondView);
make.left.mas_equalTo(self.firstView);
make.top.mas_equalTo(self.firstView.mas_bottom).offset(spaceWidth);
}];
[self.fiftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(self.secondView);
make.top.mas_equalTo(self.fourthView);
make.left.mas_equalTo(self.fourthView.mas_right).offset(spaceWidth);
}];
[self.sixView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(self.secondView);
make.left.mas_equalTo(self.fiftView.mas_right).offset(spaceWidth);
make.top.mas_equalTo(self.fourthView);
}];
}
#pragma mark - Event Response
- (void)tapRecognizer:(UITapGestureRecognizer *)tap {
NSInteger index = tap.view.tag - 1001;
if (index < self.recommendList.count) {
HomeRecommendRoomModel * recommend = [_recommendList objectAtIndex:index];
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeRecommendTableViewCell:didClickItem:)]) {
[self.delegate xPHomeRecommendTableViewCell:self didClickItem:recommend];
}
}
}
#pragma mark - Getters And Setters
- (void)setRecommendList:(NSArray *)recommendList {
_recommendList = recommendList;
if (_recommendList.count > 6) {
_recommendList = [_recommendList subarrayWithRange:NSMakeRange(0, 6)];
}
for (int i = 0; i < self.viewList.count; i++) {
XPHomeRecommendListView * recommendView = [self.viewList objectAtIndex:i];
if (i < _recommendList.count) {
HomeRecommendRoomModel * recommend = [_recommendList objectAtIndex:i];
recommendView.recommendRoomInfo = recommend;
} else {
recommendView.recommendRoomInfo = nil;
}
}
}
- (XPHomeRecommendListView *)firstView {
if (!_firstView) {
_firstView = [[XPHomeRecommendListView alloc] init];
_firstView.isLarge = YES;
_firstView.tag = 1001;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_firstView addGestureRecognizer:tap];
}
return _firstView;
}
- (XPHomeRecommendListView *)secondView {
if (!_secondView) {
_secondView = [[XPHomeRecommendListView alloc] init];
_secondView.isLarge = NO;
_secondView.tag = 1002;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_secondView addGestureRecognizer:tap];
}
return _secondView;
}
- (XPHomeRecommendListView *)thirdView {
if (!_thirdView) {
_thirdView = [[XPHomeRecommendListView alloc] init];
_thirdView.isLarge = NO;
_thirdView.tag = 1003;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_thirdView addGestureRecognizer:tap];
}
return _thirdView;
}
- (XPHomeRecommendListView *)fourthView {
if (!_fourthView) {
_fourthView = [[XPHomeRecommendListView alloc] init];
_fourthView.isLarge = NO;
_fourthView.tag = 1004;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_fourthView addGestureRecognizer:tap];
}
return _fourthView;
}
- (XPHomeRecommendListView *)fiftView {
if (!_fiftView) {
_fiftView = [[XPHomeRecommendListView alloc] init];
_fiftView.isLarge = NO;
_fiftView.tag = 1005;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_fiftView addGestureRecognizer:tap];
}
return _fiftView;
}
- (XPHomeRecommendListView *)sixView {
if (!_sixView) {
_sixView = [[XPHomeRecommendListView alloc] init];
_sixView.isLarge = NO;
_sixView.tag = 1006;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRecognizer:)];
[_sixView addGestureRecognizer:tap];
}
return _sixView;
}
@end