How to create a custom NSMenuItem - objective-c

Well, I have quite a basic question which I can't seem to find an answer to. I followed this guide to create a StatusBar menu, which works great...
However, I would like to add a custom NSMenuItem containing custom stuff. As example such as the sound slider, or the switch user account row ect.
How can I do that?
Even links to tutorials are welcome.

In most cases, you'll create a custom view containing the slider or whatever else you want to appear in the menu item. Then you call setView: on the NSMenuItem in question.
For more details, check this article from Apple's documentation:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MenuList/Articles/ViewsInMenuItems.html

Just use the setView: method of NSMenuItem.

Related

How do you create NSMenuItem similar to Dropbox's menu dropdown?

Dropbox has a wonderful new dropdown view for their menubar app. I have failed to find similiar cocoa examples to duplicate this type of view. NSMenuItem seems to be for basic lists. Any pointers in the right direction?
It's not a NSMenuItem. It is a NSStatusItem that resides in the systemwide NSStatusBar. The distinction is important, because NSStatusItems can call just about any method on any given object of your application when they're clicked.
I suspect that their NSStatusItem triggers an action that displays a borderless window.
You can find more information about status items in the Status Bar Programming Topics document.

UIActionSheet - add disabled button

Is there a way to add a disabled (non-clickable, greyed out) button to a UIActionSheet?
All I see is "addButtonWithTitle" which does not supply any properties to work with.
I believe there is no way to add disabled button in a UIActionSheet. From the class reference:
Use the UIActionSheet class to present the user with a set of
alternatives for how to proceed with a given task. You can also use
action sheets to prompt the user to confirm a potentially dangerous
action. The action sheet contains an optional title and one or more
buttons, each of which corresponds to an action to take.
If the button is disabled, it should not be added into the UIActionSheet in the first place since it is not an alternative on how to proceed with a given task.
UIActionSheet's interface doesn't really give you much control over appearance of the the whole view or the buttons.
You can use some other libraries. If you can't find one that gives such control, it would be simple to you to add that functionality. For example JLActionSheet or RDActionSheet.
You can also, try to retrieve the subviews of UIActionSheet by traversing the view stack recursively. self.view.subviews or by [[UIApplication sharedApplication].windows[0].subviews] "try both, I don't know which one is the right one". You can find the views using introspection, and find the button you want to disable.

Custom NSMenu design

Tough question. I'm looking for examples to create a custom NSMenuItem design. I want to achieve something like http://anvilformac.com/. Are there any examples out there that could put me in the right direction? Or at least a tutorial?
Apple has a section of their menu programming guide dedicated to this, and the related sample code provides a full working implementation of a custom menu view.
Drag a Custom View into your xib. Right click first Menu item and drag from the view property to the Custom View.

Placing a text field in a Menulet in Mac OS X

I'm working on an menulet-based application for the Mac that requires me to have a text field in the menu. I've searched high and low and have not found any examples of how to do this, yet I have seen many menulet apps that implement a text field. I've found no way to do it from Interface Builder, so I guess this text field would need to be defined and added to the menu programmatically.
If anyone could help me with this issue, it would be greatly appreciated.
An NSTextField is a view based subclass, therefore in code, when you create the NSMenuItem you must use the – setView: property and add the NSTextField to the menu item.
Also if you use an NSStatusItem, it also has a -setView: property.

how to add custom keyboard

I did a simple application.
My application contains 10 Text fields.
what i need is i need to hide default keypad i place manual keys like this
How can i done this keys works as a keypad to my app.
can any one pls post some code or link.
Thank u in advance.
I wrote a KeyPad, that is easy to customize via its delegate.
Just add a view with 10 buttons and assign action for each of them.
In the didBeginEditing method diss the keyboard using,
[textField resignFirstResponder]
[yourKeyboard show];
And i think apple will reject the applications using custom keyboard
There is a complete thread about that here
It has a tutorial, lots of comments, sample code and project, everything you need is there. (Is quite long though)
You basically create a view with your buttons for example and
In iOS3.2 and above you can use inputView property of your textField.
In early iOS versions you have to do a trick (add your keyboard as a subview of UIKeyboard) that is also written in the link.
If you need more advanced stuff than simple numbers, you probably want to look at UIKeyInput and UITextInput protocols.
Hope it helps