Search code examples
objective-cmacoscocoamenubarnspopover

NSPopover padding content on one side


I have two NSPopovers, both of which are set up exactly the same (just linking a custom NSView from IB). Both pop up just fine, but one appears to offset the content by about 20px.

This NSPopover is (properly) not padding the content...

no padding

but this one adds about 20px from the ride side.

padding

Here are the two views laid out in IB

enter image description here

As you can see, the search bar should be pinned to the right side like it is the left, but for some reason it is not. At first I thought it was a contraints issue, but after messing around with them for a while I can confirm it is not.

Any clue whats up?

EDIT: Decided to subclass the view and fill its rect, got some very strange results! The view appears to be offset. I have no clue why this is...

enter image description here enter image description here


Solution

  • Proplem solved, but I still don't exactly know why it required solving. The NSPopovers content view (or at least mine) requires an origin point of X: 13, Y: 13. For some reason, only one of my views was getting this value.

    To solve this, I subclassed NSView and overrode the setFrame method forcing its x and y to always be 13, 13

    -(void)setFrame:(NSRect)frameRect {
        [super setFrame:NSMakeRect(13, 13, frameRect.size.width, frameRect.size.height)];
    }