Git Product home page Git Product logo

toolbar's Introduction

toolbar (NSToolbar example)

Programmatically constructing an NSToolbar (AppKit) for macOS.

Learn how to programmatically create an NSToolbar with NSToolbarItem and specialized versions of NSToolbarItem elements such as:

in order to get expected behavior like menus, search bars, share options, and overflow items all for free.

NSToolbarItemGroup

This particular item is special in that it displays as a segmented control and will collapse into a Popup Button when space is limited.

Overflow and Visibility Priority

When a toolbar doesn't have enough space, it will start putting elements into the overflow menu. You can assign an overflow priority to your items so that some items will fall into the overflow menu before others. For example, an overflow priority of low will move that item into an overflow menu before others as horizontal space becomes more limited. See examples of this in the code.

Titlebar Accessory

The titlebar accessory view controller is an additional view that can be attached to your window's titlebar or toolbar (if one was added). This isn't part of the Toolbar but it's a good UI element to know about it since it can complement it. You can add additional UI elements appropriate to the current context of your app. This example shows how to create and add an accessory view. For more information on NSTitlebarAccessoryViewController, check out Apple's documentation.

One example of NSTitlebarAccessoryViewController is the Favorites bar in Safari on macOS. It shows a horizontal list of bookmarks you've favorited across and under the main toolbar. Just how you can toggle this Favorites bar on and off, this example code displays a toggle button as well to show or hide this accessory view.

macOS Catalina and older

As of macOS Catalina, you can also set the isBordered element to gain an NSButton look and feel for free without having to set the view property of NSToolbarItem with an NSButton.

This example also goes over how to create NSToolbarItemGroup to create an item that looks like an NSSegmentedControl that will automatically turn into a dropdown menu when space becomes limited. It will also add itself as a submenu to the overflow menu if the width space becomes severely limited.

toolbar's People

Contributors

marioaguzman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.