Custom NSMenu item - objective-c

how can i go about making a custom NSMenu for a menulet such as this?
Is this an NSMenu or is it a borderless window and if so how would i go about this?
Thanks!

It's an app running running on the OSX status bar.
See Status Bar Programming at Apple. Also, NSStatusBar and NSStatusItem
This SO post has some additional pointers:
How to create a Menubar application for Mac

More specifically it could be an NSPopover, an NSWindow, or even NSStatusItem.view's custom view. In the case of an NSWindow (often a utility form of NSPanel) (or the NSPopover) you would manually open the window when the status item is clicked, using the status item's -(void)setAction and -(void)setTarget. If you use a custom view for the status item, this would be done in -mouseDown:.
Check out this post - I found it useful.

Look at the documentation for NSStatusItem. I believe you can have it display a view instead of a standard NSMenu which is what it looks like they are doing in that image.

Related

Cocoa Finder app List view

Being a starter in Cocoa Programming, I would like to know using the existing NSTableView can one be able to achieve Disclosure Button? Or one has to follow NSOutlineview?
From the above picture, on selecting the list view and getting a Folder[Super view] and getting the children using a Disclosure button
Also can a registered Mac Developer get Finder app's sample code?
Thanks
NSOutlineView is just a subclass of NSTableView, so yes just use NSOutlineView to use the disclosure button.
Check out the docs for how to use it.
And no, Apple never released the source code for Finder.

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.

UIBarButtonItem created in Interface Builder not working - confused

I am trying to tidy up my UI by consolidating various things in a Tool Bar, and am utterly confused. I am using Interface Builder rather than constructing the controls programmatically, because my UI is fairly simple and not particularly dynamic.
What I did did so far:
Added an empty tool bar.
Dragged two previously existing and working buttons onto the tool bar. They changed their class from UIButton
to UIBarButtonItem, and the inspector now shows them as having no
Sent Actions or Referencing Outlet, but the the previous action &
outlet in the View Controller - responding to taps, setting the
label of the button - still work.
Created a new Button directly
in the tool bar. Wired up its action & outlet by ctrl-drag in the
normal way. The inspector shows the Action and Outlet for this
button as connected, which is nice, but sadly neither of them works.
Clicking the button does not invoke the action; setting the label of
the button does not cause anything to happen on the screen, even
after I tried prodding the tool bar with a setNeedsDisplay.
I'm not sure what to try next. Googling has shown me that I'm not the only person to find using UIToolBar via Interface Bulder difficult and confusing, but I haven't found a solution to my exact problem.
I don't particularly want to resort to creating my entire GUI programmatically just to tidy up a few buttons. Creating all the controls in Interface Builder outside the tool bar, getting them wired up and working, then moving them into the tool bar would presumably also work - but it would be a kludge, and would leave me still none the wiser if anything went wrong later.
Should you try using UIBarButtonItem instead of UIButton? It works for me.
i had a similar issue.
Did you created an extra UITapGestureRecognizer for root view ?
Maybe for something like > When elsewhere than UITextView clicked, resignFirstResponder for all UITextViews !
In my case, on 7.1, that extra UITapGestureRecognizer prevented transfer of event to IBAction of UIBarButtonItem which is inside an UIToolBar.
IBAction was made on Storyboard by Ctrl+Drag.
on 8.1 it was working. Not on 7.1
Read some suggestions to create an extra UIView and putting all visual elements into that extra UIView except UIToolBar

NSTextField inside NSMenu -- doesn't interact or look as expected

I'm attempting to create a log-in window inside an NSMenu (attached to the an NSStatusItem in the menu bar).
I have blank NSMenuItems in the menu. I then set the views of the menu items to NSTextFields.
It ends up looking like this:
The textfields also interact strangely. Clicking on them only gives them focus (so you can enter text) about 30% of the time.
So, I'm wondering:
-How do do I make these look better? How do I control the padding, etc?
-What's with the clicking behavior I described above? Typing only works 30% of the time.
-Are there any other apps that use such a statusbar item as a field? I'd like to take a look.
To answer your actual question instead of discussing the UI design...
Alternative:
Consider using the MAAttachedWindow project from Matt Gemmel:
Download the use an MAAttachedWindow with an NSStatusItem example.
Link:
http://mattgemmell.com/source/index.html
Quickly created example:
Used controls:
- NSTextField (Focus:None DrawsBackground:No TextColor:White)
- NSButton (Bezel:Recessed)
- NSLabel (TextColor:White)

Selecting text programmatically in menu view

I write an "Agent" Cocoa app where I have TextField in status icon's menu, it looks like this:
(source: ifotos.pl)
And in couple of places I select its contents programmatically (e.g. in -(BOOL)becomeFirstResponder of my NSTextField subclass)
And it doesn't work. It surely has something to do with the fact that it's in menu, not in window. But how do I fix that?
Because your view is in a menu, it's possible that the textfield isn't responding because the run loop is not in its default mode. Try calling selectText: like this:
[textField performSelector:#selector(selectText:) withObject:nil
afterDelay:0.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];
Why don't you just use a window instead? Menus are implemented as windows under the hood: you can do the same thing, just position and style your window appropriately.
Edit: answer largely rewritten