开发者

How can I limit the "pop-up" size of NSPopUpButton?

I have a large list - over 200 items - managed by an NSPopUpButton. When clicked, the list extends 开发者_如何转开发all the way to the top or bottom of the screen and beyond.

How can I limit the open size, so that at most 20 or so items are shown at once?


The solution I found was the following:

I subclassed NSPopUpButton, and in my subclass defined confinementRectForMenu:onScreen: (part of the NSMenuDelegate protocol). This limits the space that the list takes up. Unfortunately, you can't just specify a size but must do the work to determine the position. You can take [self frame] origin, use [[self superview] convertPointToBase:], nudge it over a bit and do whatever other calculations, then do a final conversion with [[self window] convertBaseToScreen:].


200 items is too many for a pop-up menu. The Mac Human Interface Guidelines recommend that a pop-up menu should contain a maximum of 12 items.

You need to rethink your design. I suggest that instead of the pop-up menu, you create a single-column NSTableView with no header and let your users select an item from a scrollable list of options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜