From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/screendisplay/Classes/Base/BaseView/LMJNavigationBar.m | 344 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 344 insertions(+), 0 deletions(-) diff --git a/screendisplay/screendisplay/Classes/Base/BaseView/LMJNavigationBar.m b/screendisplay/screendisplay/Classes/Base/BaseView/LMJNavigationBar.m new file mode 100755 index 0000000..e65b907 --- /dev/null +++ b/screendisplay/screendisplay/Classes/Base/BaseView/LMJNavigationBar.m @@ -0,0 +1,344 @@ +// +// LMJNavigationBar.m +// PLMMPRJK +// +// Created by NJHu on 2017/3/31. +// Copyright �� 2017��� GoMePrjk. All rights reserved. +// + +#import "LMJNavigationBar.h" + + +#define kStatusBarHeight [UIApplication sharedApplication].statusBarFrame.size.height + +#define kDefaultNavBarHeight ([UIApplication sharedApplication].statusBarFrame.size.height + 44.0) + +#define kSmallTouchSizeHeight 44.0 + +#define kLeftRightViewSizeMinWidth 60.0 + +#define kLeftMargin 0.0 + +#define kRightMargin 0.0 + +#define kNavBarCenterY(H) ((self.frame.size.height - kStatusBarHeight - H) * 0.5 + kStatusBarHeight) + +#define kViewMargin 5.0 + +@implementation LMJNavigationBar + + +#pragma mark - system + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + [self setupLMJNavigationBarUIOnce]; + } + return self; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + [self setupLMJNavigationBarUIOnce]; +} + + + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + [self.superview bringSubviewToFront:self]; + + self.leftView.frame = CGRectMake(0, kStatusBarHeight, self.leftView.lmj_width, self.leftView.lmj_height); + + self.rightView.frame = CGRectMake(self.lmj_width - self.rightView.lmj_width, kStatusBarHeight, self.rightView.lmj_width, self.rightView.lmj_height); + + self.titleView.frame = CGRectMake(0, kStatusBarHeight + (44.0 - self.titleView.lmj_height) * 0.5, MIN(self.lmj_width - MAX(self.leftView.lmj_width, self.rightView.lmj_width) * 2 - kViewMargin * 2, self.titleView.lmj_width), self.titleView.lmj_height); + + self.titleView.lmj_x = (self.lmj_width * 0.5 - self.titleView.lmj_width * 0.5); + + self.bottomBlackLineView.frame = CGRectMake(0, self.lmj_height, self.lmj_width, 0.5); + +} + + + +#pragma mark - Setter +- (void)setTitleView:(UIView *)titleView +{ + [_titleView removeFromSuperview]; + [self addSubview:titleView]; + + _titleView = titleView; + + __block BOOL isHaveTapGes = NO; + + [titleView.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { + + if ([obj isKindOfClass:[UITapGestureRecognizer class]]) { + + isHaveTapGes = YES; + + *stop = YES; + } + }]; + + if (!isHaveTapGes) { + + UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(titleClick:)]; + + [titleView addGestureRecognizer:tap]; + } + + + [self layoutIfNeeded]; +} + + + + +- (void)setTitle:(NSMutableAttributedString *)title +{ + // bug fix + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarTitleView:)] && [self.dataSource lmjNavigationBarTitleView:self]) { + return; + } + + /**������������*/ + UILabel *navTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.lmj_width * 0.4, 44)]; + + navTitleLabel.numberOfLines=0;//��������������������������� + [navTitleLabel setAttributedText:title]; + navTitleLabel.textAlignment = NSTextAlignmentCenter; + navTitleLabel.backgroundColor = [UIColor clearColor]; + navTitleLabel.userInteractionEnabled = YES; + navTitleLabel.lineBreakMode = NSLineBreakByClipping; + + self.titleView = navTitleLabel; +} + + +- (void)setLeftView:(UIView *)leftView +{ + [_leftView removeFromSuperview]; + + [self addSubview:leftView]; + + _leftView = leftView; + + + if ([leftView isKindOfClass:[UIButton class]]) { + + UIButton *btn = (UIButton *)leftView; + + [btn addTarget:self action:@selector(leftBtnClick:) forControlEvents:UIControlEventTouchUpInside]; + } + + [self layoutIfNeeded]; + +} + + +- (void)setBackgroundImage:(UIImage *)backgroundImage +{ + _backgroundImage = backgroundImage; + + self.layer.contents = (id)backgroundImage.CGImage; +} + + + +- (void)setRightView:(UIView *)rightView +{ + [_rightView removeFromSuperview]; + + [self addSubview:rightView]; + + _rightView = rightView; + + if ([rightView isKindOfClass:[UIButton class]]) { + + UIButton *btn = (UIButton *)rightView; + + [btn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside]; + } + + [self layoutIfNeeded]; +} + + + +- (void)setDataSource:(id<LMJNavigationBarDataSource>)dataSource +{ + _dataSource = dataSource; + + [self setupDataSourceUI]; +} + + +#pragma mark - getter + +- (UIView *)bottomBlackLineView +{ + if(!_bottomBlackLineView) + { + CGFloat height = 0.5; + UIView *bottomBlackLineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height , self.frame.size.width, height)]; + [self addSubview:bottomBlackLineView]; + _bottomBlackLineView = bottomBlackLineView; + bottomBlackLineView.backgroundColor = [UIColor lightGrayColor]; + } + return _bottomBlackLineView; +} + +#pragma mark - event + +- (void)leftBtnClick:(UIButton *)btn +{ + if ([self.lmjDelegate respondsToSelector:@selector(leftButtonEvent:navigationBar:)]) { + + [self.lmjDelegate leftButtonEvent:btn navigationBar:self]; + + } + +} + + +- (void)rightBtnClick:(UIButton *)btn +{ + if ([self.lmjDelegate respondsToSelector:@selector(rightButtonEvent:navigationBar:)]) { + + [self.lmjDelegate rightButtonEvent:btn navigationBar:self]; + + } + +} + + +-(void)titleClick:(UIGestureRecognizer*)Tap +{ + UILabel *view = (UILabel *)Tap.view; + if ([self.lmjDelegate respondsToSelector:@selector(titleClickEvent:navigationBar:)]) { + + [self.lmjDelegate titleClickEvent:view navigationBar:self]; + + } +} + + + +#pragma mark - custom + +- (void)setupDataSourceUI +{ + + /** ������������������ */ + + if ([self.dataSource respondsToSelector:@selector(lmjNavigationHeight:)]) { + + self.lmj_size = CGSizeMake(kScreenWidth, [self.dataSource lmjNavigationHeight:self]); + + }else + { + self.lmj_size = CGSizeMake(kScreenWidth, kDefaultNavBarHeight); + } + + /** ������������������������ */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationIsHideBottomLine:)]) { + + if ([self.dataSource lmjNavigationIsHideBottomLine:self]) { + self.bottomBlackLineView.hidden = YES; + } + + } + + /** ������������ */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarBackgroundImage:)]) { + + self.backgroundImage = [self.dataSource lmjNavigationBarBackgroundImage:self]; + } + + /** ��������� */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBackgroundColor:)]) { + self.backgroundColor = [self.dataSource lmjNavigationBackgroundColor:self]; + } + + + /** ������������������ View */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarTitleView:)]) { + + self.titleView = [self.dataSource lmjNavigationBarTitleView:self]; + + }else if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarTitle:)]) + { + /**������������*/ + self.title = [self.dataSource lmjNavigationBarTitle:self]; + } + + + /** ��������������������� view */ + /** ������������������������ */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarLeftView:)]) { + + self.leftView = [self.dataSource lmjNavigationBarLeftView:self]; + + }else if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarLeftButtonImage:navigationBar:)]) + { + UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kSmallTouchSizeHeight, kSmallTouchSizeHeight)]; + + btn.titleLabel.font = [UIFont systemFontOfSize:16]; + + UIImage *image = [self.dataSource lmjNavigationBarLeftButtonImage:btn navigationBar:self]; + + if (image) { + [btn setImage:image forState:UIControlStateNormal]; + } + + self.leftView = btn; + } + + /** ������������������ view */ + /** ������������������������ */ + if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarRightView:)]) { + + self.rightView = [self.dataSource lmjNavigationBarRightView:self]; + + }else if ([self.dataSource respondsToSelector:@selector(lmjNavigationBarRightButtonImage:navigationBar:)]) + { + UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kLeftRightViewSizeMinWidth, kSmallTouchSizeHeight)]; + + btn.titleLabel.font = [UIFont systemFontOfSize:16]; + + UIImage *image = [self.dataSource lmjNavigationBarRightButtonImage:btn navigationBar:self]; + + if (image) { + [btn setImage:image forState:UIControlStateNormal]; + } + + self.rightView = btn; + } + +} + + +- (void)setupLMJNavigationBarUIOnce +{ + self.backgroundColor = [UIColor whiteColor]; +} + + +@end + + + + + + + + + + + -- Gitblit v1.8.0