Created
January 30, 2022 21:00
-
-
Save sebjvidal/93a180b3126ea0b0c8b2d365908943d5 to your computer and use it in GitHub Desktop.
SceneDelegate: NSToolbarItem.Identifier.supplementarySidebarTrackingSeparatorItemIdentifier
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
// | |
// SceneDelegate.swift | |
// Snippet | |
// | |
// Created by Seb Vidal on 30/01/2022. | |
// | |
import UIKit | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate, NSToolbarDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) | |
let backgroundViewController = BackgroundViewController() | |
window.rootViewController = backgroundViewController | |
self.window = window | |
window.makeKeyAndVisible() | |
} | |
#if targetEnvironment(macCatalyst) | |
setupToolbar() | |
#endif | |
} | |
#if targetEnvironment(macCatalyst) | |
func setupToolbar() { | |
let toolbar = NSToolbar() | |
toolbar.delegate = self | |
window?.windowScene?.titlebar?.toolbar = toolbar | |
window?.windowScene?.titlebar?.titleVisibility = .hidden | |
} | |
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { | |
return [NSToolbarItem.Identifier("navigationButton"), .supplementarySidebarTrackingSeparatorItemIdentifier, NSToolbarItem.Identifier("otherButton")] | |
} | |
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { | |
return [NSToolbarItem.Identifier("navigationButton"), .supplementarySidebarTrackingSeparatorItemIdentifier, NSToolbarItem.Identifier("otherButton")] | |
} | |
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { | |
switch itemIdentifier { | |
case NSToolbarItem.Identifier("navigationButton"): | |
let barButtonItem = UIBarButtonItem(image: UIImage(systemName: "arrow.left"), style: .plain, target: self, action: #selector(nop(_:))) | |
return NSToolbarItem(itemIdentifier: itemIdentifier, barButtonItem: barButtonItem) | |
case NSToolbarItem.Identifier("otherButton"): | |
let barButtonItem = UIBarButtonItem(image: UIImage(systemName: "plus"), style: .plain, target: self, action: #selector(nop(_:))) | |
return NSToolbarItem(itemIdentifier: itemIdentifier, barButtonItem: barButtonItem) | |
default: | |
break | |
} | |
return NSToolbarItem(itemIdentifier: itemIdentifier) | |
} | |
@objc func nop(_ sender : NSObject) {} | |
#endif | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment