Is it possible to use a label at a toolbar?
I would like to display a number in a label. It is easy in a view but now I want it to be displayed in the toolbar.
I can drag a label to the toolbar, no problem, but the content is not visible there, even if the name Label is visible in the IB.
More info: If I drag a label into toolbar on an single view it works perfectly to display any text or number in the label even in the toolbar.
But the problem I seem to have is it does not work at a toolbar if the view is a scrollview!!
Buttons, bar buttons, no problem, but just the label does not show up when I run the app.
Why are the toolbar items behaving differently if the view is a scrollview?
It is better not to use a label for a toolbar but a UIBarButtonItem. Then you select in IB plain style and you can display the text in title.
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.
If I drag a Tab View Controller to the storyboard of an OS X application, the tab view buttons seem to misbehave. Can you help me understand what's going on?
Here's an minimal example of a fresh project, where I simply replaced the default empty View Controller with a new Tab View Controller:
The highlighted Tab View is shown as No Shadow Tab View by default, which means that the Tab View's style is Tabless in the Attributes Inspector.
There are also two Tab View Items below the Tab View in the Scene's list.
If I build & run, the result looks like this:
The tab controls are visible, but the tab view has no bezel. It seems like the tab buttons that are displayed are actually the two extra Tab View Items, not the native buttons of the Tab View itself.
If I change the Tab View's style to Top Tabs instead of the default Tabless, I get a bezel, but duplicate tab buttons:
And if I change it to Tabless With Bezel, the bezel is below the tab buttons, instead of properly sitting midway under the buttons:
I can't figure this out. Why are there two sets of tab buttons to start with (with the "real" one hidden by default)? The two extra Tab View Items seem to be completely redundant, but they can't be deleted.
Is there a way to have a tab bar with a proper bezel when using Interface Builder and a Tab View Controller?
You need to set the style of the tabViewController to "Unspecified" and setup the included tabView.
i have inserted in my app a Tab Bar controller through the storyboard.
Now i need to change images of tap when they are selected.
How can help me?
Go into the storyboard and select the view controller containing the tab you want to change (not the UITabBarController). In the inspector sidebar, you can choose the selected image and the default image. The images have to be 25x25 at 1x.
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'm trying to make my first Cocoa app (previously I was making iOS apps) and what I wish to do for my custom view is make it's title clickable with indicator (accessory) triangle facing down.
Clicking the title would open a popup/menu with my items.
How is that doneable in Cocoa?
Rdelmar's answer is probably the easiest way to go, but may not do exactly what you might want to do (which is replace the actual title with a pop up item, instead of having a popup button under the title in the toolbar area). With respect to functionality your application will probably work just as well using the toolbar.
If, however, you truly want to replace the actual title, the means of going about this would be to set the NSWindow title text to #"" to hide it, and redraw it by sticking in your own view.
[[[theWindow contentView] superview] addSubview:theSubview];
This basically tells the superview of the main content view to add another subview (direct "translation" from the code), and you'll have to tinker with the frame of this new subview to have it be positioned where the title should be positioned (as now it's free to be placed anywhere in the window frame, including on top of the title bar, as opposed to simply inside the content view).
theSubview can be your popup button, or whatever you want, and you'll also probably have to custom draw the popup button to match the original drawing of the window title.
You can do this by adding a toolbar to your window in IB. Once, you add the toolbar, you can double click on it to open the customizer view of it. Drag a popup button into the Allowable Toolbar Items area and after it is inserted there you can drag it into the bottom area which shows the layout of the toolbar -- you can also drag out any of the default items there that you don't want.