nstoolbar

NSToolbar created programmatically starts empty and won't save

∥☆過路亽.° 提交于 2020-12-06 04:45:29
问题 I'm currently trying to write a Mac application. In doing so, I'm having some peculiar problems when trying to setup an NSToolbar. Although I have setup all the components as per the API documentation, when the application loads, the toolbar always starts empty. When I open the customisation pane, the toolbar items are there, and I can drag them into the toolbar, but when I quit the application and restart the changes are gone. Note: I am aware that many of you will be of the opinion that the

How to put SwiftUI button into NSToolbar?

为君一笑 提交于 2020-05-13 03:46:41
问题 This is how SwiftUI can be inserted into NSToolbar using an accessory view controller: import SwiftUI import PlaygroundSupport var hostingView = NSHostingView(rootView: ZStack { Color.clear HStack { Text("Hey") Text("SwiftUI") } } .padding() .edgesIgnoringSafeArea(.all) ) hostingView.frame.size = hostingView.fittingSize let titlebarAccessory = NSTitlebarAccessoryViewController() titlebarAccessory.view = hostingView titlebarAccessory.layoutAttribute = .trailing let mask: NSWindow.StyleMask = [

How to disable a button of a NSToolbar of macOS X in Swift?

最后都变了- 提交于 2020-01-04 06:10:53
问题 I would like to enable and disable programmatically a toolbar item (a button) of a NSToolBar in macOS. I tried to create an outlet to ViewController control-dragging but Xcode don't accept the drop. How can I do this? I read this question about a similar question with Objective-C answers but I'm a beginner and can't understand well how to do this in Swift. 回答1: Implement the delegate method override func validateToolbarItem(_ item: NSToolbarItem) -> Bool You can distinguish the items for

Automatic Styling/Tinting of NSToolbarItem

情到浓时终转凉″ 提交于 2020-01-01 19:05:44
问题 Is there a way to tell OS X to automatically style/tint a NSToolbarItem ? I've added an "Image Toolbar Item" via IB/Xcode and set the icon to a black PDF as described in the documentation. However, my result does not resemble that of, for instance, the App Store: I'm looking for something akin to what the TabBar in iOS does by default. I'm new to OS X development... So any guidance would be appriciated! 回答1: Images need to be made template'd in order to get the correct styling (such as the

Align NSToolbarItems with NSSplitView columns

久未见 提交于 2019-12-31 00:50:11
问题 Finder and Notes have a peculiar behaviour that I am seeking to reproduce. The ‘flexible space’ in the NSToolbar seems to take the dimensions of the split view into account. For instance, the first group of buttons aligns on the left side with the right side of the sidebar. The second group of icons aligns with the right side of the first column. When I widen the sidebar, the toolbar items move along with it. Is it possible to reproduce this? Solution With the solution provided by

NSToolbarItem validation in relevant controller

折月煮酒 提交于 2019-12-22 05:42:07
问题 I have an NSToolbarItem with an NSButton as its view and an NSMenuItem in the main menu. Both have the same action, which is sent to the first responder, not to a particular target. That method is ultimately implemented in a subclass of NSSplitViewController, somewhere in the view hierarchy of the window’s content view. I want to validate both items, but have that specific split-view controller take care of the validation, because it relies on some conditions local to that controller. I

Toggle NSToolbarItem between Black and Blue

半世苍凉 提交于 2019-12-21 09:27:08
问题 I'd like to make an NSToolbarItem with a custom image which toggles between Black and Blue, like the icons at the top right of Xcode 5's main window. Peter Hosey suggested in this answer that it was as simple as setting the image to be a template, but I haven't found that to be the case. I set it to a template image, and that causes it properly render the dark gray gradient, but it doesn't render in blue when toggled. I uploaded a very simple example of what I've done, here. If someone could

Highlight NSToolbarItems

假如想象 提交于 2019-12-19 02:27:12
问题 I want to highlight the selected NSToolbarItem like e.g. in Adium (see screenshot). highlight http://a2.s3.p.quickshareit.com/files/screenshot_b28b67ba9411513d6.png Is there an easy way? If not, tell me the difficult one. =) 回答1: To expand upon Chuck's answer, you simply need to make your controller the delegate of your NSToolBar and implement the toolbarSelectableItemIdentifiers: delegate method in it. For example, the following implementation will let you retain the selection highlight on

Why does NSToolbarItem get disabled automatically?

对着背影说爱祢 提交于 2019-12-14 01:24:02
问题 I have a bit of an issue with buttons in the toolbar of my slideshow application for Mac. I want those buttons to be disabled when there is no active slideshow and enabled when there is an active slideshow. In order to achieve this, I set the buttons' isEnabled property to false at the start (I have tried both Interface Builder and my window's windowDidLoad ) and then in the didSet of my slideshow variable I do the following: var slideshow: Slideshow? { didSet { self.playPauseButton.isEnabled

Can't align label on a Segmented Control in an NSToolbar

ぐ巨炮叔叔 提交于 2019-12-13 13:14:55
问题 As you can see from the screenshot, the View button text is aligned properly under Allowed Toolbar Items, but once I add it to the toolbar, it's aligned to the right. Why? 回答1: You have to set sane minimum and maximum sizes for the toolbar item. I think you also have to make sure the autoresize masks (or constraints if you're using automatic layout) are set properly in the toolbar item's view (the NSSegmentedControl in this case). I don't have the "proper" settings handy but the min/max