86 lines
2.2 KiB
Objective-C
86 lines
2.2 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 ()
|
|
///搜索按钮
|
|
@property (nonatomic,strong) UIButton *searchButton;
|
|
///标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
@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.searchButton];
|
|
[self addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(self).offset(statusbarHeight);
|
|
make.height.mas_equalTo(44);
|
|
make.left.right.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.left.mas_equalTo(14);
|
|
make.centerY.mas_equalTo(self.titleLabel);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)searchButtonAction:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeNavView:didClickSearch:)]) {
|
|
[self.delegate xPHomeNavView:self didClickSearch:sender];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UIButton *)searchButton {
|
|
if (!_searchButton) {
|
|
_searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_searchButton setImage:[UIImage imageNamed:@"home_search"] forState:UIControlStateNormal];
|
|
[_searchButton setImage:[UIImage imageNamed:@"home_search"] forState:UIControlStateSelected];
|
|
[_searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _searchButton;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.text = AppName;
|
|
_titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Bold" size:20];
|
|
_titleLabel.textColor = [ThemeColor mainTextColor];
|
|
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
@end
|