Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create consistent toolbar buttons with icons

Desired look

I wish to make a toolbar for my app that will contain some simple buttons, each with a single monochromatic icon. Here is an example of some toolbar buttons similar to I'm trying to achieve, from Mail's compose window:

Mail compose window toolbar buttons

Notice these buttons have a consistent size, inner padding, padding, and shading. This is a pretty consistent style across macOS, present in Mail, Safari, Finder, etc. This leads me to suspect there's a standardized UI component for creating such buttons.

If I use a segmented control, each button looks correct, with each icon being correctly padded:

Segmented control

Now I would like to add individual buttons that match the style.

Attempt 1

My first attempt was to add a "Push Button" (NSButton) to the toolbar:

This resulted in a wide button that's a bit too short, and not lined up with the segmented control:

Attempt 1

Attempt 2

My second attempt was to use a segmented control, with only 1 segment.

This resulted in a button that's the right shape, size, etc., but it was off center relative to its label.

Attempt 2

Naturally, I can manually adjust the button to match the goal, but I feel like I'm missing something. What's the proper way to create these standard buttons?

like image 733
Alexander Avatar asked Sep 08 '17 13:09

Alexander


People also ask

How do I change the button on my toolbar?

In Toolbar contents, select the button whose text you want to change. Click Edit, and then enter your changes.

What is toolbar in Ui?

A Toolbar is a generalization of action bars for use within application layouts. While an action bar is traditionally part of an Activity's opaque window decor controlled by the framework, a Toolbar may be placed at any arbitrary level of nesting within a view hierarchy.

Which of the following buttons on the toolbar will help you to identify the basic configuration?

By clicking the Validation button on the toolbar, basic configuration errors can be recognized, and warnings will be displayed.

What is tool bar in swift?

SwiftUI's toolbar() modifier lets us place bar button items anywhere in the top or bottom space, but only when our view is embedded inside a NavigationView .


1 Answers

This is actually quite easy to do and you were close already. You can use NSButton for that. Note that it has different styles (defined in NSButton.BezelStyle) to choose from. The default one is the one to use inside windows and modals. But for toolbars, to match the style of segmented controls and search bars, you can choose the style .texturedRounded.

You can also set the style via Interface Builder. Note that you have to select the button itself, not the toolbar item around it.

enter image description here

To get the correct size, you seem to set the icon within the toolbar item, not the button itself.

Here is my result:

enter image description here

enter image description here

like image 137
mangerlahn Avatar answered Oct 21 '22 08:10

mangerlahn