- Supports setting a globally unified default navigation bar style (for example: backgroundColor, shadowColor, title textAttributes), and supports each view controller to customize the navigation bar style.
- Support global default settings to enable the system's own pop gesture, and support the view controller's own default settings and dynamic settings.
- Support global default setting whether to enable full-screen pop gesture, and support the view controller's own default setting and dynamic setting.
- Support global default settings for whether to display the backBarItem, as well as support for the view controller's own default settings and dynamic settings.
- Support global default settings for whether to display the navigation bar, and support the view controller's own default settings and dynamic settings.
- Support global default settings for whether to display the tab bar, and support the view controller's own default settings and dynamic settings.
- Support setting status bar style and showing hidden status.
- Support custom backBarItem.
- Support customizing the click event of the backBarItem.
- Support
Interface Builder
.
- 支持设置全局统一默认的导航栏样式(例如:导航栏背景颜色、底部分割线颜色、标题文字属性),同时支持每个视图控制器可以自定义导航栏样式
- 支持全局默认设置是否开启系统自带的返回手势,同时支持视图控制器自己默认设置和动态设置
- 支持全局默认设置是否开启全屏返回手势,同时支持视图控制器自己默认设置和动态设置
- 支持全局默认设置是否显示返回按钮,同时支持视图控制器自己默认设置和动态设置
- 支持全局默认设置是否显示导航栏,同时支持视图控制器自己默认设置和动态设置
- 支持全局默认设置是否显示标签栏,同时支持视图控制器自己默认设置和动态设置
- 支持设置状态栏样式和显示隐藏状态
- 支持自定义返回按钮
- 支持自定义返回按钮的点击事件
- 支持
Interface Builder
- iOS 12 and up
YDRootNavigationController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'YDRootNavigationController'
class MyAppAppearance: YDAppAppearanceProtocol {
var navigationBarBackgroundColor: UIColor? { .white }
var navigationBarShadowColor: UIColor? { .clear }
var titleTextAttributes: [NSAttributedString.Key : Any]? { [NSAttributedString.Key.foregroundColor: UIColor.blue] }
var backItemImage: UIImage? { UIImage(named: "nav_back_black_button") }
var backItemImageInsets: UIEdgeInsets? { UIEdgeInsets(top: 0, left: -6, bottom: 0, right: 0) }
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// 全局默认样式配置
MyAppAppearance().configure()
return true
}
}
- 导航栏控制器设置为YDRootNavigationController或继承YDRootNavigationController的类
- 代码
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.window?.rootViewController = YDRootNavigationController()
return true
}
Interface Builder
设置
class ViewController: UIViewController {
YDNavigationBarAppearence(backgroundColor: .randomColor,
titleTextAttributes: [NSAttributedString.Key.foregroundColor: UIColor.randomColor, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 20)],
shadowColor: .randomColor)
}
}
标题文字属性
导航栏背景颜色
导航栏阴影
class ViewController: UIViewController {
override var navigationBarAppearence: YDNavigationBarAppearence { YDNavigationBarAppearence(backgroundImage: UIImage.gradient(colors: [UIColor.systemPink, UIColor.purple], type: .leftToRight, size: CGSize(width: Screen.width, height: Screen.navigationBarHeight))?.addCorner(YDRectCorner(bottomLeft: 20, bottomRight: 20))) }
}
class ViewController: UIViewController {
override func backItemAction(_ sender: Any?) {
let alert = UIAlertController(title: "提示", message: "是否确定退出?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style: .default, handler: { [weak self] action in
self?.navigationController?.popViewController(animated: true)
}))
alert.addAction(UIAlertAction(title: "取消", style: .default))
present(alert, animated: true)
}
}
class ViewController: UIViewController {
// title只显示标题
override var backItemType: YDBackItemType { .title("Back") }
// title只显示图标
override var backItemType: YDBackItemType { .image(UIImage(named: "nav_circleback_button"), imageInsets: UIEdgeInsets(top: 0, left: -6, bottom: 0, right: 0)) }
// title图片加标题
override var backItemType: YDBackItemType { .all("title", titleTextAttributes: [NSAttributedString.Key.foregroundColor : UIColor.randomColor], image: UIImage(named: "nav_back_black_button"), contentInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)) }
}
class ViewController: UIViewController {
override var isHidesBackItem: Bool { true }
}
class ViewController: UIViewController {
override var backItem: UIBarButtonItem? { UIBarButtonItem(title: "BackItem", style: .plain, target: self, action: #selector(backItemAction)) }
override func backItemAction(_ sender: Any?) {
let alert = UIAlertController(title: "提示", message: "是否确定退出?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style: .default, handler: { [weak self] action in
self?.navigationController?.popViewController(animated: true)
}))
alert.addAction(UIAlertAction(title: "取消", style: .default))
present(alert, animated: true)
}
}
class ViewController: UIViewController {
// 默认设置
override var isInteractivePopGestureEnabled: Bool { interactivePopGesture }
var interactivePopGesture: Bool = true {
didSet {
// 动态设置
interactivePopGesture(interactivePopGesture)
}
}
}
class ViewController: UIViewController {
// 默认设置
override var isFullScreenPopGestureEnabled: Bool { fullScreenPopGesture }
var fullScreenPopGesture: Bool = true {
didSet {
// 动态设置
fullScreenPopGesture(fullScreenPopGesture)
}
}
}
导航栏隐藏(Navigation bar hidden)
class ViewController: UIViewController {
override var prefersNavigationBarHidden: Bool { true }
}
class ViewController: UIViewController {
override var isHidesBottomBarWhenPushed: Bool { true }
}
class ViewController: UIViewController {
override var preferredStatusBarStyle: UIStatusBarStyle { .default }
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { .none }
override var prefersStatusBarHidden: Bool { false }
}
jsone, heroyoungday@gmail.com
YDRootNavigationController is available under the MIT license. See the LICENSE file for more info.