139 lines
4.6 KiB
Objective-C
139 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) UIStackView *stackView;
|
|
@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.stackView];
|
|
[self.stackView addArrangedSubview:self.firstMenuView];
|
|
[self.stackView addArrangedSubview:self.secondMenuView];
|
|
[self.stackView addArrangedSubview:self.thirdMenuView];
|
|
self.menuViewList = @[self.firstMenuView, self.secondMenuView, self.thirdMenuView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.mas_equalTo(self.contentView).inset(15);
|
|
make.top.bottom.mas_equalTo(self.contentView);
|
|
}];
|
|
|
|
CGFloat width1 = ((KScreenWidth - 30 - 18) / 3);
|
|
[self.firstMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(width1);
|
|
}];
|
|
[self.secondMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(width1);
|
|
}];
|
|
[self.thirdMenuView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(width1);
|
|
}];
|
|
}
|
|
#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)];
|
|
}
|
|
}
|
|
|
|
- (NetImageView *)firstMenuView {
|
|
if (!_firstMenuView) {
|
|
_firstMenuView = [[NetImageView alloc] init];
|
|
_firstMenuView.userInteractionEnabled = YES;
|
|
_firstMenuView.contentMode = UIViewContentModeScaleAspectFit;
|
|
_firstMenuView.image = [UIImage imageNamed:@"home_menu_live"];
|
|
_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_menu_friend"];
|
|
_secondMenuView.contentMode = UIViewContentModeScaleAspectFit;
|
|
_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_menu_game"];
|
|
_thirdMenuView.contentMode = UIViewContentModeScaleAspectFit;
|
|
_thirdMenuView.layer.masksToBounds = YES;
|
|
_thirdMenuView.tag = 1002;
|
|
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapMenuRecognizer:)];
|
|
[_thirdMenuView addGestureRecognizer:tap];
|
|
}
|
|
return _thirdMenuView;
|
|
}
|
|
|
|
- (UIStackView *)stackView {
|
|
if (!_stackView) {
|
|
_stackView = [[UIStackView alloc] init];
|
|
_stackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_stackView.distribution = UIStackViewDistributionFill;
|
|
_stackView.alignment = UIStackViewAlignmentFill;
|
|
_stackView.spacing = 9;
|
|
}
|
|
return _stackView;
|
|
}
|
|
|
|
|
|
@end
|