I'm trying to create a menu with a drop down menu with a custom background for every cell. First i tried to adapt NSPopUpButton but i couldn't find a way to change the cells background image. Using setImage: would slide the text to the right of the background. Next I stopped at NSComboBox but i couldn't find a way to change the arrow button. Can someone please help with and idea? Next thing would be to create a custom controller but i would like to use something already done.
相关问题
- Xcode_OSX/Swift_NSPopUpButton.
- What are the correct bindings for an NSComboBox fo
- NSPopupButton in view based NSTableView: getting b
- Make NSComboBox Appear when NSTextField is clicked
- Using full width of NSPopupButton for text, no arr
相关文章
- NSPopupButton in view based NSTableView: getting b
- Make NSComboBox Appear when NSTextField is clicked
- Using full width of NSPopupButton for text, no arr
- NSPopupButton鉴于基于NSTableView的:让绑定工作(NSPopupButton
- 如何从CoreData在查看基于NSTableView的填充NSPopupButton(How to
- A popup button with a static image (Cocoa OSX)
- Separator item in NSPopupButton with bindings
- comboBoxSelectionDidChange gives me previously sel
To customise the arrow button in NSComboBox, you need to create a subclass of NSComboBoxCell and set your combo box to use that cell. If you've configured your control in IB, you can easily change the class of your cell there. If you're programmatically creating your combo box, create a subclass of NSComboBox, override
+ (Class)cellClass
and return your custom NSComboBoxCell subclass from that method.Now for the drawing. In your NSComboBoxCell subclass, you need to override
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
.(I've tried overriding
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
but the cell frame it provides stops short of drawing the actual button area, i.e. it only covers the text input area.)Your custom
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
should look something like this:I'm not sure if I understood your question correctly. If you want to show a menu at an arbitrary position somewhere in your UI: NSMenu provides convenience methods for achieving that. Have a look at the documentation for
+ popUpContextMenu:withEvent:forView:
,+ popUpContextMenu:withEvent:forView:withFont:
and– popUpMenuPositioningItem:atLocation:inView:
to find the one that best fits your needs. Like that you can display a menu at whatever position you like.If you instead want to display arbitrary content inside a menu, have a look at the documentation of
NSMenuItem
's- setView:
. This allows you to insert views inside menus. Together with the above method of displaying menus wherever you want, you can create all sorts of solutions for "PopOver" needs.