Constraints are putting NSView 0.5 pixels away from where it should be

Has anyone seen something like this before?

(lldb) po self.constraintsAffectingLayout(for: .horizontal)
▿ 5 elements
  - 0 : <NSLayoutConstraint:0x60000243f2f0 H:|-(NSSpace(20))-[MyApp.MyCustomButton:0x7fe67e83b000'Some Label']   (active, names: '|':MyApp.MySuperView:0x7fe68d7073f0 )>
  - 1 : <NSLayoutConstraint:0x60000243e1c0 H:[MyApp.MyCustomButton:0x7fe67e83b000'Some Other Label']-(NSSpace(20))-|   (active, names: '|':MyApp.MySuperView:0x7fe68d7073f0 )>
  - 2 : <NSAutoresizingMaskLayoutConstraint:0x6000024046e0 h=-&- v=-&- MyApp.MySuperView:0x7fe68d7073f0.minX == 0   (active, names: '|':NSThemeFrame:0x7fe68d735be0 )>
  - 3 : <NSAutoresizingMaskLayoutConstraint:0x600002404730 h=-&- v=-&- H:[MyApp.MySuperView:0x7fe68d7073f0]-(0)-|   (active, names: '|':NSThemeFrame:0x7fe68d735be0 )>
  - 4 : <NSLayoutConstraint:0x600002426a80 'NSWindow-current-width' NSThemeFrame:0x7fe68d735be0.width == 465 priority:500   (active)>

(lldb) p self.frame
(NSRect) $R1 = (origin = (x = 19.5, y = 19.5), size = (width = 426, height = 81))

It appears that per the constraints, this should be 20 pixels from the edge of the screen, but instead it's 19.5. As you may expect, this is causing the button to draw all blurry on non-Retina displays.

Anyone seen anything like this before and/or know what sort of thing could cause something like this? Is there anything I should look for to debug this?

Accepted Reply

Hi all,

Turns out that the custom superclass of my custom button class had an alignmentRectInsets override that I forgot was in there. 🤦 Leaving this here in case anyone else runs into the same problem.

Replies

Hi all,

Turns out that the custom superclass of my custom button class had an alignmentRectInsets override that I forgot was in there. 🤦 Leaving this here in case anyone else runs into the same problem.