175 lines
4.6 KiB
Objective-C
175 lines
4.6 KiB
Objective-C
//
|
|
// XPHomeSectionView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/2/21.
|
|
//
|
|
|
|
#import "XPHomeSectionView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+Home.h"
|
|
|
|
@interface XPHomeSectionView ()
|
|
///标志的容器
|
|
@property (nonatomic,strong) UIStackView *logoStackView;
|
|
///显示图片
|
|
@property (nonatomic,strong) UIImageView *logoImageView;
|
|
///显示标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///更多的容器
|
|
@property (nonatomic,strong) UIStackView *moreStackView;
|
|
///更多
|
|
@property (nonatomic,strong) UILabel *moreLabel;
|
|
///箭头
|
|
@property (nonatomic,strong) UIImageView *arrowImageView;
|
|
///点击更多
|
|
@property (nonatomic,strong) UIControl *moreControl;
|
|
@end
|
|
|
|
@implementation XPHomeSectionView
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.logoStackView];
|
|
[self addSubview:self.moreStackView];
|
|
[self addSubview:self.moreControl];
|
|
|
|
[self.logoStackView addArrangedSubview:self.logoImageView];
|
|
[self.logoStackView addArrangedSubview:self.titleLabel];
|
|
[self.moreStackView addArrangedSubview:self.moreLabel];
|
|
[self.moreStackView addArrangedSubview:self.arrowImageView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.logoStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self).offset(15);
|
|
make.centerY.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(20, 20));
|
|
}];
|
|
|
|
[self.moreStackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(self).offset(-15);
|
|
make.centerY.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(6, 10));
|
|
}];
|
|
|
|
[self.moreControl mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.right.mas_equalTo(self);
|
|
make.width.mas_equalTo(200);
|
|
}];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)moreControlAction:(UIControl *)sender {
|
|
if (!self.isHiddenMore && self.delegate && [self.delegate respondsToSelector:@selector(didClickXPHomeSectionView:)]) {
|
|
[self.delegate didClickXPHomeSectionView:self];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setImageName:(NSString *)imageName {
|
|
_imageName = imageName;
|
|
if (_imageName.length > 0) {
|
|
self.logoImageView.image = [UIImage imageNamed:_imageName];
|
|
}
|
|
}
|
|
|
|
- (void)setTitle:(NSString *)title {
|
|
_title = title;
|
|
if (_title.length > 0) {
|
|
self.titleLabel.text = _title;
|
|
}
|
|
}
|
|
|
|
- (void)setIsHiddenLogo:(BOOL)isHiddenLogo {
|
|
_isHiddenLogo = isHiddenLogo;
|
|
self.logoImageView.hidden = _isHiddenLogo;
|
|
}
|
|
|
|
- (void)setIsHiddenMore:(BOOL)isHiddenMore {
|
|
_isHiddenMore = isHiddenMore;
|
|
self.moreStackView.hidden = _isHiddenMore;
|
|
}
|
|
|
|
- (UIStackView *)logoStackView {
|
|
if (!_logoStackView) {
|
|
_logoStackView = [[UIStackView alloc] init];
|
|
_logoStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_logoStackView.distribution = UIStackViewDistributionFill;
|
|
_logoStackView.alignment = UIStackViewAlignmentCenter;
|
|
_logoStackView.spacing = 2;
|
|
}
|
|
return _logoStackView;
|
|
}
|
|
|
|
- (UIStackView *)moreStackView {
|
|
if (!_moreStackView) {
|
|
_moreStackView = [[UIStackView alloc] init];
|
|
_moreStackView.axis = UILayoutConstraintAxisHorizontal;
|
|
_moreStackView.distribution = UIStackViewDistributionFill;
|
|
_moreStackView.alignment = UIStackViewAlignmentCenter;
|
|
_moreStackView.spacing = 2;
|
|
}
|
|
return _moreStackView;
|
|
}
|
|
|
|
- (UILabel *)moreLabel {
|
|
if (!_moreLabel) {
|
|
_moreLabel = [[UILabel alloc] init];
|
|
_moreLabel.text = @"更多";
|
|
_moreLabel.font = [UIFont systemFontOfSize:12];
|
|
_moreLabel.textColor = [ThemeColor textThirdColor];
|
|
}
|
|
return _moreLabel;
|
|
}
|
|
|
|
- (UIImageView *)arrowImageView {
|
|
if (!_arrowImageView) {
|
|
_arrowImageView = [[UIImageView alloc] init];
|
|
_arrowImageView.userInteractionEnabled = YES;
|
|
_arrowImageView.image = [UIImage imageNamed:@"home_recommend_room_more"];
|
|
}
|
|
return _arrowImageView;
|
|
}
|
|
|
|
- (UIImageView *)logoImageView {
|
|
if (!_logoImageView) {
|
|
_logoImageView = [[UIImageView alloc] init];
|
|
}
|
|
return _logoImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
|
_titleLabel.textColor = [ThemeColor mainTextColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIControl *)moreControl {
|
|
if (!_moreControl) {
|
|
_moreControl = [[UIControl alloc] init];
|
|
[_moreControl addTarget:self action:@selector(moreControlAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _moreControl;
|
|
}
|
|
|
|
@end
|