Skip to content

Instantly share code, notes, and snippets.

@sebjvidal
Created January 30, 2022 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebjvidal/93a180b3126ea0b0c8b2d365908943d5 to your computer and use it in GitHub Desktop.
Save sebjvidal/93a180b3126ea0b0c8b2d365908943d5 to your computer and use it in GitHub Desktop.
SceneDelegate: NSToolbarItem.Identifier.supplementarySidebarTrackingSeparatorItemIdentifier
//
// 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