Skip to content

Commit

Permalink
修复bug #78,优化创建导航栏item方法
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintGao committed May 20, 2021
1 parent c66e321 commit d113a11
Show file tree
Hide file tree
Showing 31 changed files with 742 additions and 363 deletions.
2 changes: 1 addition & 1 deletion GKNavigationBar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GKNavigationBar'
s.version = '1.5.6'
s.version = '1.5.7'
s.license = 'MIT'
s.summary = '自定义导航栏--导航栏联动'
s.homepage = 'https://github.com/QuintGao/GKNavigationBar'
Expand Down
27 changes: 26 additions & 1 deletion GKNavigationBar/NavigationBar/UIBarButtonItem+GKNavigationBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,38 @@ NS_ASSUME_NONNULL_BEGIN

@interface UIBarButtonItem (GKNavigationBar)

// 纯文字
+ (instancetype)gk_itemWithTitle:(NSString *)title target:(id)target action:(SEL)action;
+ (instancetype)gk_itemWithTitle:(NSString *)title font:(nullable UIFont *)font target:(id)target action:(SEL)action;
+ (instancetype)gk_itemWithTitle:(NSString *)title color:(nullable UIColor *)color target:(id)target action:(SEL)action;
+ (instancetype)gk_itemWithTitle:(NSString *)title color:(nullable UIColor *)color font:(nullable UIFont *)font target:(id)target action:(SEL)action;

// 纯图片
+ (instancetype)gk_itemWithImage:(UIImage *)image target:(id)target action:(SEL)action;
+ (instancetype)gk_itemWithImage:(UIImage *)image color:(nullable UIColor *)color target:(id)target action:(SEL)action;
+ (instancetype)gk_itemWithImage:(nullable UIImage *)image highLightImage:(nullable UIImage *)highLightImage target:(id)target action:(SEL)action;

// 文字+图片
+ (instancetype)gk_itemWithTitle:(nullable NSString *)title image:(nullable UIImage *)image target:(id)target action:(SEL)action;

+ (instancetype)gk_itemWithImage:(nullable UIImage *)image highLightImage:(nullable UIImage *)highLightImage target:(id)target action:(SEL)action;

/// 快速创建导航栏item
/// @param title 标题
/// @param titleColor 标题颜色
/// @param font 字体
/// @param image 图片
/// @param imageColor 图片颜色
/// @param highLightImage 高亮图片
/// @param target 点击方法实现目标类
/// @param action 点击方法
+ (instancetype)gk_itemWithTitle:(nullable NSString *)title
titleColor:(nullable UIColor *)titleColor
font:(nullable UIFont *)font
image:(nullable UIImage *)image
imageColor:(nullable UIColor *)imageColor
highLightImage:(nullable UIImage *)highLightImage
target:(id)target
action:(SEL)action;

@end

Expand Down
50 changes: 30 additions & 20 deletions GKNavigationBar/NavigationBar/UIBarButtonItem+GKNavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,53 @@
//

#import "UIBarButtonItem+GKNavigationBar.h"
#import "UIImage+GKNavigationBar.h"

@implementation UIBarButtonItem (GKNavigationBar)

+ (instancetype)gk_itemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title image:nil target:target action:action];
return [self gk_itemWithTitle:title color:nil target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title font:(UIFont *)font target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title color:nil font:font target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title color:color font:nil target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title color:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title titleColor:color font:font image:nil imageColor:nil highLightImage:nil target:target action:action];
}

+ (instancetype)gk_itemWithImage:(UIImage *)image target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:nil image:image target:target action:action];
return [self gk_itemWithImage:image color:nil target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title image:(UIImage *)image target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title image:image highLightImage:nil target:target action:action];
+ (instancetype)gk_itemWithImage:(UIImage *)image color:(UIColor *)color target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:nil titleColor:nil font:nil image:image imageColor:color highLightImage:nil target:target action:action];
}

+ (instancetype)gk_itemWithImage:(UIImage *)image highLightImage:(UIImage *)highLightImage target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:nil image:image highLightImage:highLightImage target:target action:action];
return [self gk_itemWithTitle:nil titleColor:nil font:nil image:image imageColor:nil highLightImage:highLightImage target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title image:(UIImage *)image target:(id)target action:(SEL)action {
return [self gk_itemWithTitle:title titleColor:nil font:nil image:image imageColor:nil highLightImage:nil target:target action:action];
}

+ (instancetype)gk_itemWithTitle:(NSString *)title image:(UIImage *)image highLightImage:(UIImage *)highLightImage target:(id)target action:(SEL)action {
+ (instancetype)gk_itemWithTitle:(NSString *)title titleColor:(UIColor *)titleColor font:(UIFont *)font image:(UIImage *)image imageColor:(UIColor *)imageColor highLightImage:(UIImage *)highLightImage target:(id)target action:(SEL)action {
UIButton *button = [UIButton new];
if (title) {
[button setTitle:title forState:UIControlStateNormal];
}
if (image) {
[button setImage:image forState:UIControlStateNormal];
}
if (highLightImage) {
[button setImage:highLightImage forState:UIControlStateHighlighted];
}
if (title) [button setTitle:title forState:UIControlStateNormal];
if (titleColor) [button setTitleColor:titleColor forState:UIControlStateNormal];
if (font) button.titleLabel.font = font;
if (imageColor) image = [UIImage gk_changeImage:image color:imageColor];
if (image) [button setImage:image forState:UIControlStateNormal];
if (highLightImage) [button setImage:highLightImage forState:UIControlStateHighlighted];
[button sizeToFit];
if (button.bounds.size.width < 44.0f) button.bounds = CGRectMake(0, 0, 44.0f, 44.0f);
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];

if (button.bounds.size.width < 44.0f) {
button.bounds = CGRectMake(0, 0, 44.0f, 44.0f);
}

return [[self alloc] initWithCustomView:button];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ + (void)load {

- (void)gk_viewDidLoad {
// bug fix #76,修改添加了子控制器后调整导航栏间距无效的bug
// 当创建了gk_navigationBar或者父控制器是导航控制器的时候才去调整导航栏间距
// 当创建了gk_navigationBar并且父控制器是导航控制器的时候才去调整导航栏间距
if ([self navItemSpaceChangeIfNeeded]) {
// 设置默认导航栏间距
self.gk_navItemLeftSpace = GKNavigationBarItemSpace;
Expand All @@ -54,6 +54,7 @@ - (void)gk_viewDidLoad {
}
// 如果是根控制器,取消返回按钮
if (self.navigationController && self.navigationController.childViewControllers.count <= 1) {
if (!self.gk_NavBarInit) return;
self.gk_navLeftBarButtonItem = nil;
}
[self gk_viewDidLoad];
Expand Down
Loading

0 comments on commit d113a11

Please sign in to comment.