Files
mier_ios/SweetParty/Expand/YBKit/CustomNavigationView.m

303 lines
8.6 KiB
Mathematica
Raw Permalink Normal View History

2025-08-11 10:43:19 +08:00
//
// CustomNavigationView.m
// LefenStore1.0
//
// Created by LGY on 2017/10/19.
// Copyright © 2017 lefen58.com. All rights reserved.
//
#define LineColor COLOR16(0xe7e7e7)
#define NavFontColor COLOR16(0x333333)
#import "CustomNavigationView.h"
@implementation CustomNavigationView
#pragma mark -- init
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initView];
}
return self;
}
- (void)initView
{
__weak typeof(self) weakSelf = self;
self.backgroundColor = [UIColor whiteColor];
[self.cusNavView addSubview:self.left0Btn];
[self.cusNavView addSubview:self.left1Btn];
[self.cusNavView addSubview:self.titleImg];
[self.cusNavView addSubview:self.titleLab];
[self.cusNavView addSubview:self.right1Btn];
[self.cusNavView addSubview:self.right0Btn];
[self.cusNavView addSubview:self.rightTitleBtn];
[self addSubview:self.bgImg];
[self addSubview:self.cusNavView];
[self addSubview:self.btmLine];
[self.titleImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(weakSelf.cusNavView.mas_centerX);
make.centerY.equalTo(weakSelf.cusNavView.mas_centerY);
}];
[self.rightTitleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(weakSelf.cusNavView.mas_right).offset(-20);
make.centerY.equalTo(weakSelf.cusNavView.mas_centerY);
make.height.mas_equalTo(44);
}];
}
#pragma mark -- handleAction
- (void)cus_setNavTitle:(NSString *)title
{
if (title) {
self.titleLab.text = title;
}
}
- (void)cus_setNavBackgroundColor:(UIColor *)color
{
self.backgroundColor = color;
}
- (void)cus_setNavBackgroundImage:(UIImage *)image
{
if (image) {
self.bgImg.image = image;
}
}
- (void)cus_setNavTintColor:(UIColor *)color
{
if (color) {
self.left0Btn.tintColor = color;
self.left1Btn.tintColor = color;
self.right1Btn.tintColor = color;
self.right0Btn.tintColor = color;
self.rightTitleBtn.tintColor = color;
}
}
- (void)cus_setNavTitleColor:(UIColor *)color
{
if (color) {
self.titleLab.textColor = color;
}
}
// 0 1 2 ++ 3+ 4
- (void)cus_setNavShow:(NSInteger)type
{
self.left0Btn.hidden = YES;
self.left1Btn.hidden = YES;
self.right0Btn.hidden = YES;
self.right1Btn.hidden = YES;
self.rightTitleBtn.hidden = YES;
switch (type) {
case 0: {
self.left0Btn.hidden = NO;
}
break;
case 1: {
self.left0Btn.hidden = NO;
self.right0Btn.hidden = NO;
}
break;
case 2: {
self.left0Btn.hidden = NO;
self.right0Btn.hidden = NO;
self.right1Btn.hidden = NO;
}
break;
case 3: {
self.left0Btn.hidden = NO;
self.rightTitleBtn.hidden = NO;
}
break;
default:
break;
}
}
- (void)handleBack:(id)sender
{
if (self.handleBackBlock) {
self.handleBackBlock();
} else {
if (self.viewController.navigationController) {
[self.viewController.navigationController popViewControllerAnimated:YES];
} else {
[self.viewController dismissViewControllerAnimated:YES completion:nil];
}
}
}
- (void)handleGuanbi:(id)sender
{
if (self.handleGuanBiBlock) {
self.handleGuanBiBlock();
}
}
- (void)handleRight0Btn:(id)sender
{
if (self.handleRight0Block) {
self.handleRight0Block();
}
}
- (void)handleRightBtn1:(id)sender
{
if (self.handleRight1Block) {
self.handleRight1Block();
}
}
- (void)handleRightTitleBtn:(id)sender
{
if (self.handleRightTitleBlock) {
self.handleRightTitleBlock();
}
}
#pragma mark -- lazyLoad
- (UIImageView *)bgImg
{
if (!_bgImg) {
_bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, APPW, yb_NavigationBar_H)];
_bgImg.contentMode = UIViewContentModeScaleAspectFill;
_bgImg.layer.masksToBounds = YES;
}
return _bgImg;
}
- (UIView *)cusNavView
{
if (!_cusNavView) {
_cusNavView = [[UIView alloc] initWithFrame:CGRectMake(0, yb_StatusBar_H, APPW, 44)];
}
return _cusNavView;
}
- (UIView *)btmLine
{
if (!_btmLine) {
_btmLine = [[UIView alloc] initWithFrame:CGRectMake(0, yb_StatusBar_H + 43.5, APPW, 0.5)];
_btmLine.backgroundColor = LineColor;
_btmLine.hidden = NO;
}
return _btmLine;
}
- (UIButton *)left0Btn
{
if (!_left0Btn) {
_left0Btn = [UIButton buttonWithType:UIButtonTypeCustom];
_left0Btn.frame = CGRectMake(0, 0, 44, 44);
_left0Btn.contentMode = UIViewContentModeScaleAspectFit;
_left0Btn.titleLabel.font = [UIFont systemFontOfSize:14];
_left0Btn.titleLabel.textColor = NavFontColor;
_left0Btn.tintColor = NavFontColor;
[_left0Btn setImage:[UIImage imageNamed:@"blackBack"] forState:UIControlStateNormal];
[_left0Btn addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
}
return _left0Btn;
}
- (UIButton *)left1Btn
{
if (!_left1Btn) {
_left1Btn = [UIButton buttonWithType:UIButtonTypeSystem];
_left1Btn.frame = CGRectMake(44, 0, 44, 44);
_left1Btn.contentMode = UIViewContentModeScaleAspectFit;
_left1Btn.titleLabel.font = [UIFont systemFontOfSize:14];
_left1Btn.titleLabel.textColor = NavFontColor;
_left1Btn.tintColor = NavFontColor;
[_left1Btn setTitle:@"关闭" forState:UIControlStateNormal];
[_left1Btn addTarget:self action:@selector(handleGuanbi:) forControlEvents:UIControlEventTouchUpInside];
_left1Btn.hidden = YES;
}
return _left1Btn;
}
- (UIImageView *)titleImg
{
if (!_titleImg) {
_titleImg = [[UIImageView alloc] init];
_titleImg.contentMode = UIViewContentModeScaleAspectFit;
_titleImg.layer.masksToBounds = YES;
_titleImg.hidden = YES;
[_titleImg sizeToFit];
}
return _titleImg;
}
- (UILabel *)titleLab
{
if (!_titleLab) {
_titleLab = [[UILabel alloc] initWithFrame:CGRectMake(88, 0, APPW - 176, 44)];
_titleLab.textColor = NavFontColor;
_titleLab.font = [UIFont systemFontOfSize:18 weight:0.3];
_titleLab.textAlignment = NSTextAlignmentCenter;
}
return _titleLab;
}
- (UIButton *)right0Btn
{
if (!_right0Btn) {
_right0Btn = [UIButton buttonWithType:UIButtonTypeCustom];
_right0Btn.frame = CGRectMake(APPW - 44, 0, 44, 44);
_right0Btn.contentMode = UIViewContentModeScaleAspectFit;
_right0Btn.titleLabel.font = [UIFont systemFontOfSize:14];
_right0Btn.titleLabel.textColor = NavFontColor;
_right0Btn.tintColor = NavFontColor;
[_right0Btn setImage:[UIImage imageNamed:@"navMore"] forState:UIControlStateNormal];
[_right0Btn addTarget:self action:@selector(handleRight0Btn:) forControlEvents:UIControlEventTouchUpInside];
_right0Btn.hidden = YES;
}
return _right0Btn;
}
- (UIButton *)right1Btn
{
if (!_right1Btn) {
_right1Btn = [UIButton buttonWithType:UIButtonTypeCustom];
_right1Btn.frame = CGRectMake(APPW - 88, 0, 44, 44);
_right1Btn.contentMode = UIViewContentModeScaleAspectFit;
_right1Btn.titleLabel.font = [UIFont systemFontOfSize:14];
_right1Btn.titleLabel.textColor = NavFontColor;
_right1Btn.tintColor = NavFontColor;
[_right1Btn setImage:[UIImage imageNamed:@"special"] forState:UIControlStateNormal];
[_right1Btn addTarget:self action:@selector(handleRightBtn1:) forControlEvents:UIControlEventTouchUpInside];
_right1Btn.hidden = YES;
}
return _right1Btn;
}
- (UIButton *)rightTitleBtn
{
if (!_rightTitleBtn) {
_rightTitleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_rightTitleBtn.contentMode = UIViewContentModeScaleAspectFit;
_rightTitleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[_rightTitleBtn setTitleColor:HEXCOLOR(0x666666) forState:UIControlStateNormal];
[_rightTitleBtn addTarget:self action:@selector(handleRightTitleBtn:) forControlEvents:UIControlEventTouchUpInside];
_rightTitleBtn.hidden = YES;
[_rightTitleBtn sizeToFit];
}
return _rightTitleBtn;
}
- (void)styleClear {
self.backgroundColor = UIColor.clearColor;
self.btmLine.hidden = YES;
}
- (void)styleBackWhite {
[self.left0Btn setImage:[UIImage imageNamed:@"BM_Tools_White_arrow_left"] forState:UIControlStateNormal];
self.titleLab.textColor = UIColor.whiteColor;
}
@end