Get specific Item of NSToolbar - swift

I want to have a NSToolbar in my macOS-App. I have created a Toolbar in the Window of my storyboard and connected this with a swift class called MainToolbar.
The source text of this class is the following (at this moment):
import Cocoa
class MainToolbar: NSToolbar, NSToolbarDelegate {
override init(identifier: String) {
super.init(identifier: identifier)
}
}
Now, I want to change the title of the Colors-Element and add a share button as two examples.
The Colors-Element has the identifier "NSToolbarShowColorsItem" in the storyboard.
I know, that there is the possibility of getting the items with "self.items", but there is now way of adding elements because it is immutable. And I also cannot find the way of getting elements with the identifier.

In order to do this you have to go to the storyboard and click on the toolbar.
The toolbar will open up and show two sections. The top section is the available buttons and the bottom section is the default buttons for the application.
I don't think it is wise to actually change the standard buttons, i.e. change the meaning of Colors. It is better to add a new NSToolbarItem to the top section. After you added it, you can double click on the title to give it a title and you can set the image by providing an image name in the Attribute Inspector.
Next you drag the new button from the top section to the bottom section.
Actions should be set from the top section and not from the bottom section.

Related

Full height layout with NSSplitViewController with a Toolbar

I am working on a text editor app that needs an inspector sidebar for special actions with the text. I am therefore using an NSSplitViewController to manage the overall layout. I want the sidebar to take advantage of macOS' new full-height sidebars. I already have an NSWindow with a fullSizeContentView style mask. And my corresponding NSSplitViewItem has the property allowsFullHeightLayout set to true.
Unfortunately, I am still getting this layout:
Additional information:
The Inspector sidebar is an NSHostingView with a SwiftUI View wrapped inside.
When using the accessibility inspector, I can see that the sidebar layout is expanded all the way up, but the NSToolbar seems to be ignoring it.
I need to keep both the title and toolbar
It is possible to let the toolbar know that there's a split view divider by using a special NSToolbarItem. By creating a custom identifier and rendering it as an NSTrackingSeparatorToolbarItem, I was able to extend the line all the way up.
To make the inspector view background extend to full height layout, I had to use window.titlebarAppearsTransparent = true.
This blogpost helped me to figure out everything: https://christiangiacomi.com/posts/setup-nstrackingseparatortoolbaritem-macos11/

Common UIToolbar for the required pages - Xcode 8.3

Please suggest that how we can create common UIToolbar(with bar items) for the required pages?
I know that we can add custom UIBarButtonItem in each view controller.
Assuming you use storyboard. First, drag a UIToolBar item to your storyboard.
Next, set up the location of the tool bar. In my example, I put it on the bottom with padding 0 to left, right and bottom. The height is set to be 44
Finally, drag as many Bar Button Item as you want to your tool bar, and then add spaces between them. You can either use fixed length spaces, or the flexible ones (which are used in this example) by simply drag them between the bar button items.

Can underline, but not bold text in NSTextView

I have an NSDocuments & storyboard app created with the wizard in Xcode 8. In the ViewController Scene I have added a NSTextView. Certain menu items are disabled, such as Bold and Italic.
Looking at the First Responder the actions for bold and italic are not there. Am I supposed to write these methods myself? Is this due to the responder chain not being correctly set up? Why does underline show up but not bold?
Edit: Adding an image to show how I can edit text with the Inspector Bar, but the Format menu does not show the commands I would expect.
There is a historical (?) reason of this problem.
When the main menu was created in a xib file, xib file automatically contained a NSFontManager instance and such menu items like Bold were connected to it.
However in a modern storyboard, there is no preset NSFontManager instance.
Well then, you can connect them to a FontManager manually following the following steps.
Create a normal Object instance (blue cube) in the Application scene.
Change class of the Object instance to NSFontManager.
Connect the menu items to addFontTrait(_:) action of the fontManager. Likewise, connect "Bigger" and "Smaller" items to modifyFont(_:).
You also need to set menuItems' tag, however they are actually already set. Set the correspondent tag also manually only if menuItem's tag is 0.
If you ctrl drag from menu item to first responder, in menu view, you get the same options, just ctrl click. Then you implement whatever function you just connected. If you connect File > New to newDocument and implement in your ViewController
func newDocument(_ sender: Any?){
print("func newDocument(_ sender: Any? \(String(describing: sender)))")
}
It will get called. First responder lists all the same methods as the added Object with NSFontManager as class. I don't use #IBAction in front of method because I don't connect it.

How to create a toolbar in a TableView with a Label?

I would like to add a toolbar with a label entitled "Save your search?" on the left and a button "Save" on the right that triggers a specific action when tapped. How could I do that programmatically, especially I want this Toolbar to show up only when a particular View is loaded on a screen but not on every view.
Also, I want the toolbar to have a static image as background. "Save" button will also have a static image for background
Just to check; why do you need to add this toolbar of sorts onto a TableView? Depending on how you've set things up; and specially seeing that you need to conditionally hide/show this toolbar, might be easier to add it outside the tableView (just above it I guess).
Seeing as you need to hide/show this toolbar at will; guess you can simply use a UIView for it and add the UIButtons on top as subviews; --> declare it as a property in the .h file so that it can be freely accessed in the .m file whenever you need to hide / show it.
Did you need help on some specific issue related to this perhaps; or would this serve as a goo enough starting point?

iPhone UI controls

Which class is used to create the clickable sections(with > arrow) and the checkbox list on last shot?
alt text http://developer.apple.com/iphone/library/documentation/uikit/reference/UINavigationController_Class/Art/navigation_interface.jpg
Have a look at the UINavigationController.
To create the list with arrows, use the UITableView and set the Accessory "Disclosure indicator" on the cell (in the Interface builder).
The screenshot is from the Settings application though. If you want to create subpanels for settings, you need to use a different approach (Here is one example)
UITableView (UITableViewController).
The checkmarks and arrows are added by changing the .accessoryType property of the cell. To make the table views clickable, implement the -tableView:didSelectRowAtIndexPath: method in the delegate.