Files
yinmeng-ios/xplan-ios/Main/Home/View/SubViews/XPHomeNavView.m
2022-04-02 00:19:42 +08:00

156 lines
5.3 KiB
Objective-C

//
// XPHoneNavView.m
// xplan-ios
//
// Created by 冯硕 on 2021/11/29.
//
#import "XPHomeNavView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor+Home.h"
#import "XPMacro.h"
#import "UIImage+Utils.h"
@interface XPHomeNavView ()<UITextFieldDelegate>
///排行榜
@property (nonatomic,strong) UIButton *rankButton;
///开启自己的房间
@property (nonatomic,strong) UIButton *openRoomButton;
///搜索
@property (nonatomic,strong) UIButton *searchButton;
///滑块
@property (nonatomic,strong) JXCategoryTitleView *titleView;
@end
@implementation XPHomeNavView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.titleView];
[self addSubview:self.rankButton];
[self addSubview:self.openRoomButton];
[self addSubview:self.searchButton];
}
- (void)initSubViewConstraints {
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self).offset(12);
make.height.mas_equalTo(40);
make.centerY.mas_equalTo(self.rankButton);
make.width.mas_equalTo(200);
}];
[self.rankButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(22, 22));
make.right.mas_equalTo(-14);
make.top.mas_equalTo(statusbarHeight + 14);
}];
[self.openRoomButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.rankButton);
make.right.mas_equalTo(self.rankButton.mas_left).offset(-20);
}];
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.centerY.mas_equalTo(self.rankButton);
make.right.mas_equalTo(self.openRoomButton.mas_left).offset(-20);
}];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
#pragma mark - Event Response
- (void)searchButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeNavView:didClickSearch:)]) {
[self.delegate xPHomeNavView:self didClickSearch:sender];
}
}
- (void)rankButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeNavView:didClickRank:)]) {
[self.delegate xPHomeNavView:self didClickRank:sender];
}
}
- (void)openRoomButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeNavView:didClickOpenRoom:)]) {
[self.delegate xPHomeNavView:self didClickOpenRoom:sender];
}
}
#pragma mark - Getters And Setters
- (UIButton *)rankButton {
if (!_rankButton) {
_rankButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_rankButton setImage:[UIImage imageNamed:@"home_nav_rank"] forState:UIControlStateNormal];
[_rankButton setImage:[UIImage imageNamed:@"home_nav_rank"] forState:UIControlStateSelected];
[_rankButton addTarget:self action:@selector(rankButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _rankButton;
}
- (UIButton *)searchButton {
if (!_searchButton) {
_searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_searchButton setImage:[UIImage imageNamed:@"home_nav_search"] forState:UIControlStateNormal];
[_searchButton setImage:[UIImage imageNamed:@"home_nav_search"] forState:UIControlStateSelected];
[_searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _searchButton;
}
- (UIButton *)openRoomButton {
if (!_openRoomButton) {
_openRoomButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_openRoomButton setImage:[UIImage imageNamed:@"home_nav_open_room"] forState:UIControlStateNormal];
[_openRoomButton setImage:[UIImage imageNamed:@"home_nav_open_room"] forState:UIControlStateSelected];
[_openRoomButton addTarget:self action:@selector(openRoomButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _openRoomButton;
}
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectZero];
_titleView.backgroundColor =[UIColor clearColor];
_titleView.titleColor = UIColorFromRGB(0x444444);
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
_titleView.titleFont = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
_titleView.titleSelectedFont = [UIFont systemFontOfSize:24 weight:UIFontWeightHeavy];
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.averageCellSpacingEnabled = NO;
_titleView.defaultSelectedIndex = 0;
_titleView.cellSpacing = 20;
_titleView.contentEdgeInsetLeft = 15;
JXCategoryIndicatorImageView *lineView = [[JXCategoryIndicatorImageView alloc] init];
lineView.indicatorImageViewSize = CGSizeMake(48, 12);
lineView.verticalMargin = 6;
lineView.indicatorImageView.image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xFFC000), UIColorFromRGB(0xFFD15A)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(48, 12)];
lineView.indicatorImageView.layer.masksToBounds = YES;
lineView.indicatorImageView.layer.cornerRadius = 6;
_titleView.indicators = @[lineView];
}
return _titleView;
}
@end