'How can I customize an NSToolbarItem to make it look completely different?

I'm programming an iOS app to run on macOS via MacCatalyst.

I know how to create an NSToolbar and populate it with all sorts of premade items using this code:

SceneDelegate.h

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    
#if TARGET_OS_MACCATALYST
    // Code specific to Mac.
    
    self.mainToolbar = [[NSToolbar alloc] initWithIdentifier:@"mainToolbar"];
    self.mainToolbar.delegate = self;
    
    [(UIWindowScene*)scene titlebar].separatorStyle = UITitlebarSeparatorStyleNone;
    [(UIWindowScene*)scene titlebar].toolbar = self.mainToolbar;
    [(UIWindowScene*)scene titlebar].toolbarStyle = UITitlebarToolbarStyleUnified;
    [(UIWindowScene*)scene titlebar].titleVisibility = UITitlebarTitleVisibilityHidden;
    
#else
    // Code to exclude from Mac.
#endif

}

- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
     itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier
 willBeInsertedIntoToolbar:(BOOL)flag {
    
    NSToolbarItem *testButton = [[NSToolbarItem alloc] initWithItemIdentifier:@"button1"];
    
    testButton.title = @"Test";
    
    return testButton;
}

It looks like this:

enter image description here

But what I'm looking for is to be able to create my own custom NSToolbarItem that looks completely different. For example, Chrome on macOS is obviously using a custom NSToolbar or NSToolbarItem in order to create the tab bar:

enter image description here

According to Apple, the NSToolbarItem has a view property that I can play with? This view is nowhere to be found in Xcode:

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source