Toolbar buttons are disabled by default for Lion Cocoa app - cocoa

I've created an interface nib/xib file. The app is basically working, which is cool. The standard toolbar buttons look bad, they're glossy and raised, while most apps in Lion have the flat, inner bevel look. So I created some image toolbar buttons and put them in the toolbar and they look great, but they're all disabled by default.
Is there a way to give these the correct state in InterfaceBuilder or do I have to use code to give them the proper state.
Cocoa and Objective C are very unfamiliar so it would be helpful to me if I just knew what to search for. Most of my searching brings me results for creating custom buttons for iOS.

I figured this out, here's what you do:
In the nib/xib file, double click your menu bar to show the "allowed toolbar items" sheet. From here, choose your button that you've created. In my case I'll select a back button that I want to connect to a webview control. Ctrl click + drag from the button to what you want to connect it to and then make the appropriate connection. In my case I choose goBack from the WebView.
Once it has a connection it now becomes active.

Related

How do you make a button automatically press without user interaction in Swift Cocoa

This sounds like a weird question, but I am using Swift 2.0 and Xcode to create a cocoa app, and I have a popover linked to an invisible button. I wan't to activate it so it pops up after the user has been on the page for a little while. I have a timer set, but I can't figure out the code to get the button to actually activate at that time, so that the popover will show. I am using a button so I can have an access spot for the popover to show at.
Right now, if you click the (invisible) button, everything shows perfectly. However, I need the click to activate programmatically. I would really appreciate any help!
Thanks!

Open new window uppon NSAlert

I'm using a NSAlert to ask the user to enable Accessibility for assistive devices. Is it possible to have a button that does not close the NSAlert that I could use to just open the UniversalAccess prefpane ?
If not, I suppose I've to create myself that window.
Thx.
Normally alerts close when any button is pressed. In Mac OS X 10.5 or later you can use setAccessoryView: to insert a custom view into the alert, which presumably can contain a button that does anything you want.
Note however that you can't specify where the accessory view goes. It might have a button in it but the button would show up in the middle of the window instead of along the bottom with the other buttons. (If you chose a different button style such as a square bevel for your custom button, it might look less out of place.) To have complete control over layout, you need to make your own alert window.

How to load second view in Preference window cocoa

I am developing a cocoa application for mac. I have created a preference window with four buttons in toolbar. I am loading views on click event of buttons. Its working fine.
What I want to know is how to load another view on click of button in a view. Like in preference window of Safari, there is tab named with Privacy. And there is a button 'Details...' in Privacy tab. When we click on that button it shows a new view which shows a list of cookies.
Any Idea how to load view like view loaded on click of 'Details...' button???
There are several approaches, depending on what you're trying to accomplish. The easiest is probably to create the view you want, but make it hidden when you don't want it to be visible. Then when the user presses the "Details…" button, make it visible (and possibly expand the window if necessary) by calling [-NSView setHidden:NO].
Another way is to make the view a separate view in your .nib file, and when the "Details…" button is pressed, insert the view into the appropriate window using [-NSView addSubView:].
You could also create the view at runtime when the user presses the "Details…" button. That seems like a lot of work, though.

Programmatically controlling a Cocoa Button on OSX (making it invisible and pressed)

I am trying to interface with a cocoa popup menu from an OpenGL button. The actual button needs to be in OpenGL and I cannot stick an actual Cocoa button in its place but when this button is pressed I would like for a Cocoa menu to popup just like the one that comes up when you press the nspopupbutton. It seems that there is no way to get this popup window to come up by itself so I wanted to just insert an invisible button and have it be pressed automatically when the popup menu method is called. Is there a way to programmatically set a button to pressed (this will bring up the menu from the popupbutton) and make the button itself invisible without making the resulting menu invisible?
It seems that there is no way to get this popup window to come up by itself
Sure there is. See + popUpContextMenu:withEvent:forView:
Have you thought about just using a regular NSMenu, rather than trying to finagle the menu from an NSPopupButton?

how do you display an NSMenu programmatically?

I wrote a little app that lives in the NSStatusBar. I want to have a global shortcut that when hit, the menu bar's content is displayed, exactly like the behavior of spotlight.
I have added a global key shortcut to my application, but I am unable to get the meun bar to display. How can I do this? I tried with "popUpContextMenu" , but that method displays the menu in the bottom left hand corner, I want the menu to open up right under the NSStatusBar menu icon.
You can do it, apple provides a method for it popUpStatusItemMenu:
I don't think there is a supported way to do this without perhaps using the Accessibility framework to simulate a click on your status item. Regardless, it's probably not a good idea to abuse a menu in this way.
The Spotlight menu bar item does not use an NSMenu, it uses a custom window/view. You might consider going this route if you have some sort of custom view to display.

Resources