1
votes

I'm writing a status menu app, with a big image centered in one of the menu items. So far, it's been working well—until I tried to set a minimum width on the status menu.

When I press the ⌥ (Option) key, to use an alternate menu item, the custom view with the image in it resizes itself to the size it would be if there were no minimum width.

Here's some images illustrating the problem, before and after holding ⌥. The gray color is a custom view that should stretch to cover the full width.

before after

The problem persists as long as the menu is open, even after releasing ⌥, but goes away when the menu is closed and reopened until ⌥ is pressed again.

My system version is Mac OS X v10.12.6 (Sierra). My autoresizing mask for the view is this:

let autoresizingMask: NSView.AutoresizingMask = [.minXMargin, .minYMargin, .maxXMargin, .maxYMargin, .width, .height]

Edit: If I make the view centered in the menu item and not stretch (without the .width and .height), it still moves to the left.

1

1 Answers

0
votes

I just realized that the solution is extremely simple. I just needed to set the frame width of my custom view to the minimum width of the status menu.

let r = NSRect(x: 0, y: 0, width: statusMenuMinWidth, height: h)