Writing an app for macOS using Xcode 8.2. After adding a toolbar to my window and a NSSegmentedControl, the label View for the toolbar item is not centered. Both in the storyboard and as the app is running.
Why?
It looks to me like the size of your toolbar item is mismatched to the size of the view. If you change the maximum size of your toolbar item so that it can't expand beyond the size of the segmented control, you should be good to go.
Related
I want to have a window with a hidden title, as seen in Safari or Xcode, but using a titlebar accessory view instead of a toolbar (I want more control over arrangement and content than a toolbar provides). Is this doable?
I haven't quite been able to make it work. If I set my window's titleVisibility to hidden, and my accessory view's layoutAttribute is bottom, then the title area is empty except for the standard close/minimize/zoom buttons, and my accessory view appears below that.
If I change the layoutAttribute to right, then my accessory view appears to the right of the standard buttons where I want it, but the bottom is cut off because the title bar isn't tall enough, and the view also doesn't resize horizontally with the window.
Is there a way to make this work? Or do I have to use a toolbar?
Update: I used Xcode's visual debugger to examine Xcode's own title bar, and found that it is using a toolbar. The debugger refuses to attach to Safari, so I'm left wondering how it does the new tab button. I imagine that button is a right-pinned accessory view, and the rest is a normal toolbar. Safari's toolbar is still customizable, so that seems most likely.
I decided to go ahead and use a toolbar, and it's working pretty well.
I took my NSTitleBarAccessoryController subclass and made it inherit from NSViewController instead.
I created a non-customizable toolbar for my window, with a single "Image Toolbar Item" in both the allowed and default sets.
The toolbar item has a height of 32 and a max width of 10000 so it can stretch to fill the title bar.
In my toolbar delegate, in toolbarWillAddItem:, I instantiate the view controller from the nib and put its view into the item.
A text label that is effectively the new window title has its value bound to the window's title.
To match the spacing in Xcode's title bar, use a left and right margin of 1 pixel (zero will cut off the edges) and a top margin of 5.
window.titleVisibility = .hidden moves the toolbar into the title area.
How do you change the width of a button in a tool bar on Mac? I can change the width in interface builder but it only updates if the width is larger than the current size. If I try to make it smaller it doesn't change in tool bar.
Not sure if you found an answer yet, but I was recently looking to do this as well for a popup button. The answer is to create the button outside the toolbar first. Then once you create it you can drag it onto the toolbar area and it will be added as a toolbar item.
For example, I created a popup button on my main window and set it to the width that I wanted. Then I opened the toolbar section and dragged that button onto it... and it worked.
Good luck.
I have a very simple application.
There is a toolbar on the top, and the bottom.
The bottom toolbar needs to be in a UIScrollView because it's buttons goes off the screen.
But when I test my application on a iPhone 4G, the scrollbar, and it's content, doesn't display.
When I test it on a iPod 5G, everything is where it should be.
I'm not using any coding currently, this is all being done in the storyboard.
Since there is a difference in the screen size of iPhone4G and iPod 5 the UI will resize resulting in the shrinking of all added subviews.
There are two solutions to fix your problem.
1) Add both toolbars. Select the toolbar at the bottom of the screen and in the Editor menu
Editor > Embed In > Scroll View
This will make sure that the UI works out of the box.
2) This is the second way (I am guessing you've created your UI this way)
-> Drag a scroll view
-> Add Tool bar as its sub view.
-> Now we need to set the springs (In our case autolayout attributes.)
The image below will help you understand better
The first constraint "Height Equals" can be added as follows
Editor > Pin > Height
Now Select and edit the leading space to: attribute
and in the drop down menu select "Less than or Equal"
This is similar to setting "UIViewAutoresizingFlexibleTopMargin" as the auto resizing mask.
I noticed an odd behavior in Interface Builder (Xcode 4):
Dropping a plain old Push Button directly on the content view of a window results in a small button with the font "System Mini 9".
When I drop the button on a custom view I get the expected "normal" button with the font "System 13". See screenshot.
Why is that and is there a way to always get the "normal" size even when placing the button on the content view?
BTW: I tried changing the font size of the smaller button, the label changes, but the button height remains tiny.
The height is affected by the control size (which is an enum and not to be confused with the control’s frame size). Use the Size inspector (ruler icon) to change it to Regular. To do this programmatically set the controlSize property to NSRegularControlSize.
So I'm using the method:
[someWindow setContentBorderThickness:24.0 forEdge:NSMaxYEdge];
But I can't seem to get the toolbar to increase in height. It simply stays the same as in default. Can anyone shed some light here?
An NSToolbar is automatically resized to accommodate the height of the tallest NSToolbarItem. The standard (large) toolbar items are all 32 px tall, so the toolbar has no need to make itself larger. If you do something like add a custom view toolbar item, then it will be resized to accommodate that item, as shown in the image below:
(To accomplish the result shown above, I clicked on the toolbar twice in IB to bring down the Allowed Toolbar Items sheet, then dragged an NSView custom view from the library palette onto that sheet).
P.S. I'd recommend using this capability with discretion.
You cannot specify an arbitrary height for NSToolbar. You can, however, specify a size mode. A toolbar with 24x24-pixel icons has a small size mode:
[toolbar setSizeMode: NSToolbarSizeModeSmall];
which is equivalent to Size: Small in Interface Builder’s Attributes Inspector.