Swiftpack.co - spirit-jsb/Koinu as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by spirit-jsb.
spirit-jsb/Koinu 1.0.7
Custom UINavigationController framework for iOS
⭐️ 1
🕓 3 weeks ago
iOS
.package(url: "https://github.com/spirit-jsb/Koinu.git", from: "1.0.7")

Koinu (小犬)

Koinu 是一个自定义 UINavigationController 框架,通过为每一个 UIViewController 维护单独的 UINavigationController 从而使开发者便捷的设置 NavigationBar 视觉样式。

视图结构

VMNavigationController
   ┌─VMContainerViewController
   │    ──VMContainerNavigationController
   │         ──firstViewController
   │
   └─VMContainerViewController
        ──VMContainerNavigationController
             ──secondViewController
/// 获取得到的是 `VMContainerNavigationController`
self.navigationController

/// 获取得到的是 `VMNavigationController`
self.vm.navigationController

示例代码

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  let viewController: UIViewController = ...
  
  let rootNavigationController = VMNavigationController(rootViewController: viewController)

  self.window.rootViewController = rootNavigationController
  
  return true
}
/// 禁用侧滑返回
self.vm.disableInteractivePop = true

/// 通过重写 `navigationBarClass` 实现自定义 `UINavigationBar`
override var navigationBarClass: AnyClass? {
  return CustomNavigationBar.self
}
/// 使用系统样式的 `backBarButtonItem`
self.vm.navigationController.vm.useSystemBackBarButtonItem = true

/// 使用根视图的 `navigationBar` 属性
self.vm.navigationController.vm.useRootNavigationBarAttributes = true

UITabBarController 设置

VMNavigationController
   ──VMContainerViewController
       ──VMContainerNavigationController
            ──UITabBarController
                 ┌─VMContainerViewController
                 │    ──firstViewController
                 │
                 ├─VMContainerViewController
                 │    ──secondViewController
                 │
                 ├─VMContainerViewController
                 │    ──thirdViewController
                 │
                 └─VMContainerViewController
                      ──fourthViewController
let tabBarController = UITabBarController()

if #available(iOS 13.0, *) {
  tabBarController.tabBar.standardAppearance = appearance
}
if #available(iOS 15.0, *) {
  tabBarController.tabBar.scrollEdgeAppearance = appearance
}

let firstViewController = UIViewController()
firstViewController.tabBarItem = UITabBarItem(title: "First", image: UIImage ..., selectedImage: UIImage ...)

let secondViewController = UIViewController()
secondViewController.tabBarItem = UITabBarItem(title: "Second", image: UIImage ..., selectedImage: UIImage ...)

let thirdViewController = UIViewController()
thirdViewController.tabBarItem = UITabBarItem(title: "Third", image: UIImage ..., selectedImage: UIImage ...)

let fourthViewController = UIViewController()
fourthViewController.tabBarItem = UITabBarItem(title: "Fourth", image: UIImage ..., selectedImage: UIImage ...)

tabBarController.viewControllers = [
  VMContainerNavigationController(rootViewController: firstViewController),
  VMContainerNavigationController(rootViewController: secondViewController),
  VMContainerNavigationController(rootViewController: thirdViewController),
  VMContainerNavigationController(rootViewController: fourthViewController)
]

let navigationController = VMNavigationController(noWrappingRootViewController: tabBarController)

self.window.rootViewController = rootNavigationController
──UITabBarController
      ┌─VMNavigationController
      │   -─VMContainerViewController
      │       ──VMContainerNavigationController
      │           ──firstViewController
      |─VMNavigationController
      │   -─VMContainerViewController
      │       ──VMContainerNavigationController
      │           ──secondViewController
      |─VMNavigationController
      │   -─VMContainerViewController
      │       ──VMContainerNavigationController
      │           ──thirdViewController
      └─VMNavigationController
          -─VMContainerViewController
              ──VMContainerNavigationController
                  ──fourthViewController
let tabBarController = UITabBarController()

if #available(iOS 13.0, *) {
  tabBarController.tabBar.standardAppearance = appearance
}
if #available(iOS 15.0, *) {
  tabBarController.tabBar.scrollEdgeAppearance = appearance
}

let firstViewController = UIViewController()
firstViewController.tabBarItem = UITabBarItem(title: "First", image: UIImage ..., selectedImage: UIImage ...)

let secondViewController = UIViewController()
secondViewController.tabBarItem = UITabBarItem(title: "Second", image: UIImage ..., selectedImage: UIImage ...)

let thirdViewController = UIViewController()
thirdViewController.tabBarItem = UITabBarItem(title: "Third", image: UIImage ..., selectedImage: UIImage ...)

let fourthViewController = UIViewController()
fourthViewController.tabBarItem = UITabBarItem(title: "Fourth", image: UIImage ..., selectedImage: UIImage ...)

tabBarController.viewControllers = [
  VMNavigationController(rootViewController: firstViewController),
  VMNavigationController(rootViewController: secondViewController),
  VMNavigationController(rootViewController: thirdViewController),
  VMNavigationController(rootViewController: fourthViewController)
]

self.window.rootViewController = tabBarController

限制条件

  • iOS 11.0+
  • Swift 5.0+

安装

Swift Package Manager

https://github.com/spirit-jsb/Koinu.git

作者

spirit-jsb, [email protected]

许可文件

Koinu 可在 MIT 许可下使用,更多详情请参阅许可文件。

GitHub

link
Stars: 1
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

version 1.0.7
3 weeks ago

publish version 1.0.7

  • optimized code
  • dump deploymentTarget to iOS 11.0

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics