136 lines
4.6 KiB
Objective-C
136 lines
4.6 KiB
Objective-C
//
|
|
// XPHomeMenuTableViewCell.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/2/21.
|
|
// 扩列交友 心动匹配 小游戏
|
|
|
|
#import "XPHomeMenuTableViewCell.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "NetImageView.h"
|
|
#import "XPMacro.h"
|
|
///Model
|
|
#import "HomeMenuInfoModel.h"
|
|
|
|
@interface XPHomeMenuTableViewCell ()
|
|
@property (nonatomic,strong) NetImageView *firstMenuView;
|
|
@property (nonatomic,strong) NetImageView *secondMenuView;
|
|
@property (nonatomic,strong) NetImageView *thirdMenuView;
|
|
///自view的数组
|
|
@property (nonatomic,strong) NSArray<NetImageView *> *menuViewList;
|
|
@end
|
|
|
|
@implementation XPHomeMenuTableViewCell
|
|
|
|
- (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.firstMenuView];
|
|
[self.contentView addSubview:self.secondMenuView];
|
|
[self.contentView addSubview:self.thirdMenuView];
|
|
self.menuViewList = @[self.firstMenuView, self.secondMenuView, self.thirdMenuView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
CGFloat width1 = (KScreenWidth - 30 - 8) * 176 / (176 + 82 + 80);
|
|
CGFloat width2 = (KScreenWidth - 30 - 8) * 82 / (176 + 82 + 80);
|
|
CGFloat width3 = (KScreenWidth - 30 - 8) * 80 / (176 + 82 + 80);
|
|
[self.firstMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(15);
|
|
make.bottom.mas_equalTo(0);
|
|
make.height.mas_equalTo(60);
|
|
make.width.mas_equalTo(width1);
|
|
}];
|
|
[self.secondMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.firstMenuView.mas_right).mas_offset(4);
|
|
make.bottom.mas_equalTo(0);
|
|
make.height.mas_equalTo(60);
|
|
make.width.mas_equalTo(width2);
|
|
}];
|
|
[self.thirdMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.secondMenuView.mas_right).mas_offset(4);
|
|
make.bottom.mas_equalTo(0);
|
|
make.height.mas_equalTo(60);
|
|
make.width.mas_equalTo(width3);
|
|
}];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)onTapMenuRecognizer:(UITapGestureRecognizer *)tap {
|
|
UIView * view = [tap view];
|
|
HomeMenuInfoModel * homeInfoModel = [self.menuList objectAtIndex:view.tag -1000];
|
|
if (homeInfoModel && self.delegate && [self.delegate respondsToSelector:@selector(xPHomeMenuTableViewCell:didClickMenuInfo:)]) {
|
|
[self.delegate xPHomeMenuTableViewCell:self didClickMenuInfo:homeInfoModel];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setMenuList:(NSArray *)menuList {
|
|
_menuList = menuList;
|
|
NSMutableArray * array = [_menuList mutableCopy];
|
|
if (_menuList.count > 3) {
|
|
_menuList = [array subarrayWithRange:NSMakeRange(0, 3)];
|
|
}
|
|
|
|
for (int i = 0; i< _menuList.count; i++) {
|
|
NetImageView * imageView = [self.menuViewList objectAtIndex:i];
|
|
HomeMenuInfoModel * menuInfoModel = [_menuList objectAtIndex:i];
|
|
imageView.imageUrl = menuInfoModel.icon;
|
|
}
|
|
}
|
|
|
|
- (NetImageView *)firstMenuView {
|
|
if (!_firstMenuView) {
|
|
_firstMenuView = [[NetImageView alloc] init];
|
|
_firstMenuView.userInteractionEnabled = YES;
|
|
_firstMenuView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_firstMenuView.layer.masksToBounds = YES;
|
|
_firstMenuView.tag = 1000;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapMenuRecognizer:)];
|
|
[_firstMenuView addGestureRecognizer:tap];
|
|
}
|
|
return _firstMenuView;
|
|
}
|
|
|
|
- (NetImageView *)secondMenuView {
|
|
if (!_secondMenuView) {
|
|
_secondMenuView = [[NetImageView alloc] init];
|
|
_secondMenuView.userInteractionEnabled = YES;
|
|
_secondMenuView.image = [UIImage imageNamed:@"home_recommend_icon"];
|
|
_secondMenuView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_secondMenuView.layer.masksToBounds = YES;
|
|
_secondMenuView.tag = 1001;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapMenuRecognizer:)];
|
|
[_secondMenuView addGestureRecognizer:tap];
|
|
}
|
|
return _secondMenuView;
|
|
}
|
|
|
|
- (NetImageView *)thirdMenuView {
|
|
if (!_thirdMenuView) {
|
|
_thirdMenuView = [[NetImageView alloc] init];
|
|
_thirdMenuView.userInteractionEnabled = YES;
|
|
_thirdMenuView.image = [UIImage imageNamed:@"home_recommend_icon"];
|
|
_thirdMenuView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_thirdMenuView.layer.masksToBounds = YES;
|
|
_thirdMenuView.tag = 1002;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapMenuRecognizer:)];
|
|
[_thirdMenuView addGestureRecognizer:tap];
|
|
}
|
|
return _thirdMenuView;
|
|
}
|
|
|
|
|
|
@end
|