Zenith 1.0.1

Zenith 1.0.1

Wess Cope维护。



Zenith 1.0.1

  • 作者
  • Wess Cope

Zenith

Zenith是一个用于简化视图控制器和视图管理的框架,您的控制器将负责管理交互和其他类似的“控制器”功能。它还包括一个路由器,可以简化在应用程序中的导航。

要求

  • iOS 11.0+
  • Xcode 9.0
  • Swift 4.0

安装

CocoaPods

CocoaPods是Objective-C和Swift的依赖管理器。
要了解如何在CocoaPods中设置您的项目,请参阅官方文档
要使用CocoaPods将Zenith集成到Xcode项目中,您必须将其添加到项目的Podfile中。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'

use_frameworks!

target '<Your Target Name>' do
  pod 'Zenith', '~> 1.0'
end

之后,运行以下命令

$ pod install

使用方法

Zenith 允许视图控制器将视图布局和管理委托给一个组件。

import UIKit
import Zenith

class MyViewComponent : ViewComponent {
  private lazy var label:UILabel = {
    let label = UILabel()
    label.textAlignment = .center
    label.text = "Hello, world"
    
    return label
  }()
  
  override setupConstraints() {
    label.addConstraints([
      // Add constraints here
    ])
  }
  
  override render() -> UIView {
    return children(
     label
    )
  }
}

class MyViewController : ViewController<MyViewComponent> {
  // Your view controller will now load the component and
  // present it, like normal.
}

Zenith 还提供了一个路由器以简化导航。

import Zenith

enum MyRoute : RouteOption {
  case home
  case about

  var controller:UIViewController {
    switch self {
    case .home:
      return UINavigationController(rootViewController: MyHomeViewController)
    case .about:
      return UINavigationController(rootViewController: MyAboutViewController)
    }
  }
}

// Create an instance of your router, where you can access it anywhere.

let router = Router<MyRoute>()
router.move(.home)

致谢

Zenith 由 Wess Cope 编写和维护。
Twitter: @wesscope.

许可

Zenith 采用 MIT 许可。
详细信息请参阅 LICENSE