-
-
Save bubudrc/50632d76aa5c0a76f950ae694c82f24b to your computer and use it in GitHub Desktop.
A sample UIKit app that sets up a four column layout with new iOS 14 API on UISplitViewController.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class FourColumnsContainerViewController: UIViewController { | |
let outerSplitViewController = UISplitViewController(style: .tripleColumn) | |
let innerSplitViewController = UISplitViewController(style: .doubleColumn) | |
let primary = makeContentViewController("App") | |
let secondary = makeContentViewController("Files") | |
let mainContent = makeContentViewController("File Content") | |
let inspector = makeContentViewController("Inspector") | |
init() { | |
outerSplitViewController.primaryEdge = .leading | |
innerSplitViewController.primaryEdge = .trailing | |
innerSplitViewController.preferredSplitBehavior = .tile | |
outerSplitViewController.maximumPrimaryColumnWidth = 120 | |
innerSplitViewController.maximumPrimaryColumnWidth = 200 | |
outerSplitViewController.primaryBackgroundStyle = .sidebar | |
innerSplitViewController.setViewController(mainContent, for: .secondary) | |
innerSplitViewController.setViewController(inspector, for: .primary) | |
outerSplitViewController.setViewController(primary, for: .primary) | |
outerSplitViewController.setViewController(secondary, for: .supplementary) | |
outerSplitViewController.setViewController(innerSplitViewController, for: .secondary) | |
// MARK: - Boring stuff below here | |
super.init(nibName: nil, bundle: nil) | |
addChild(outerSplitViewController) | |
outerSplitViewController.didMove(toParent: self) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(outerSplitViewController.view) | |
} | |
override func viewWillLayoutSubviews() { | |
super.viewWillLayoutSubviews() | |
outerSplitViewController.view.frame = view.bounds | |
} | |
@available(*, unavailable) | |
override var splitViewController: UISplitViewController? { | |
nil | |
} | |
@available(*, unavailable) required init?(coder: NSCoder) { preconditionFailure() } | |
} | |
private let makeContentViewController: (String) -> UINavigationController = { title in | |
let vc = UIViewController() | |
vc.title = title | |
vc.view.backgroundColor = .systemBackground | |
return UINavigationController(rootViewController: vc) | |
} | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var _window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let windowScene = scene as! UIWindowScene | |
let window = UIWindow(windowScene: windowScene) | |
window.rootViewController = FourColumnsContainerViewController() | |
window.makeKeyAndVisible() | |
_window = window | |
} | |
} | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment