Files
yinmeng-ios/xplan-ios/Main/Home/View/Cell/XPHomeRecommendTableViewCell.m

194 lines
6.3 KiB
Mathematica
Raw Normal View History

2022-02-21 20:06:09 +08:00
//
// XPHomeRecommendTableViewCell.m
// xplan-ios
//
// Created by on 2022/2/21.
//
#import "XPHomeRecommendTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
///View
2022-02-25 21:18:01 +08:00
#import "XPHomeRecommendListView.h"
2022-02-21 20:06:09 +08:00
2022-02-25 21:18:01 +08:00
@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;
2022-02-21 20:06:09 +08:00
@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;
2022-02-25 21:18:01 +08:00
[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];
2022-02-21 20:06:09 +08:00
}
- (void)initSubViewConstraints {
2022-02-25 21:18:01 +08:00
CGFloat spaceWidth = 11 * kScreenScale;
2022-07-19 16:07:29 +08:00
CGFloat miniWidth = (KScreenWidth - 30 - spaceWidth * 2) / 3.0;
CGFloat bigWidth = miniWidth * 2 + spaceWidth;
2022-02-25 21:18:01 +08:00
[self.firstView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-07-19 16:07:29 +08:00
make.size.mas_equalTo(CGSizeMake(bigWidth, bigWidth));
2022-02-25 21:18:01 +08:00
make.left.mas_equalTo(self.contentView).offset(15);
make.top.mas_equalTo(self.contentView);
}];
[self.secondView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-07-19 16:07:29 +08:00
make.size.mas_equalTo(CGSizeMake(miniWidth, miniWidth));
2022-02-25 21:18:01 +08:00
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);
2022-02-21 20:06:09 +08:00
}];
2022-02-25 21:18:01 +08:00
[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 {
2022-03-01 19:28:16 +08:00
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];
}
}
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
#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;
}
}
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
- (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;
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
- (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];
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
return _secondView;
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
- (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;
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
- (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;
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
- (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];
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
return _sixView;
2022-02-21 20:06:09 +08:00
}
2022-02-25 21:18:01 +08:00
2022-02-21 20:06:09 +08:00
@end