一行代码设置状态栏样式和导航栏背景颜色、标题、按钮、透明度以及全屏pop手势支持。
- 为每个控制器定制了UINavigationBar支持(颜色、透明度、字体大小)
- 全屏pop手势返回
- 为单个控制器关闭pop手势支持
- 自定义pop手势范围
- 支持自定义UINavigationBar
iOS 8.0+
Xcode 8.0+
-
Cocoapods
- 在
podfile里面添加pod 'STNavigationBar', '~> 版本号' pod install
- 在
-
手动拖入
下载代码并将
STNavigaionBar文件夹拖入到项目中,导入头文件#import "STNavigationBar.h"即可。
建议在AppDelegate里全局设置导航栏以及状态栏样式。
- 设置全局导航栏样式
[UIColor st_setDefaultNavigationBarBarTintColor:STMainNavBarColor];
[UIColor st_setDefaultNavigationBarTintColor:STNaviBarTintColor];
[UIColor st_setDefaultNavigationBarTitleColor:STNaviBarTitleColor];
[UIColor st_setDefaultStatusBarStyle:UIStatusBarStyleLightContent];
- 设置单个控制器导航栏样式
// 设置导航栏两边按钮颜色
[self st_setNavigationBarTintColor:[UIColor whiteColor]];
// 设置导航栏标题颜色
[self st_setNavigationBarTitleColor:[UIColor blackColor]];
// 设置状态栏样式
[self st_setStatusBarStyle:UIStatusBarStyleDefault];
// 设置导航栏透明度
[self st_setNavigationBarBackgroundAlpha:0];
// 设置导航栏背景颜色
[self st_setNavigationBarTitleColor:[UIColor whiteColor]];
- 开启/关闭手势返回
// YES:关闭手势/NO:开启手势
[self st_setInteractivePopDisabled:YES];
- 指定手势返回范围
[self st_setInteractivePopMaxAllowedInitialDistanceToLeftEdge:30.0];
- 解决UIScrollView和手势pop冲突
// 自定义一个UIScrollView,实现如下方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (self.contentOffset.x <= 0) {
if ([otherGestureRecognizer.delegate isKindOfClass:[STFullscreenPopGestureRecognizerDelegate class]]) {
return YES;
}
}
return NO;
}
- 如果你发现了bug,请帮我提交issue。
- 如果你有好的建议,请帮我提交issue。
- 如果你想贡献代码,请提交请求。
STNavigationBar 是基于 MIT 许可证下发布的,详情请参见 LICENSE。





