Why are the two buttons limited by the ZERO distance between them and not the flush?

I have read in many places that the constraints in Cocoa AutoLayout act on the visual boundaries of the control / view in question, so the following bewilderment (2me):

In Xcode IB, I add / drag two ( push button

) buttons to the view (one below the other) and constrain them so that they have zero vertical spacing between them. I expect the two buttons to merge with each other vertically.

The result is two buttons that have a slight difference / space between them, which can be checked visually or by looking at the alignment rectangle values ​​in Xcode. In this case, the extra distance between them seems to be 1 point.

taken in Xcode 6

Below is a screenshot of the constraints between a simple view hierarchy:

view hierarchy and constraints

Also, confirming the above, when you change the constant in the constraint to -1, the two buttons appear flush with each other.

buttons with vertical difference of -1.0

The above applies to OS X 10.10 (Yosemite).

The stranger is still in my actual application (the above is just a test case for the SO question), when I stack a lot NSButton

vertically (programmatically, not via IB), I need to provide a -4.0 constraint in between (as opposed to -1.0 above ) to make them flush. The elementless button for this button looks like this (Swift):

        self.bezelStyle = NSBezelStyle.RoundedBezelStyle

      

[While it doesn't make sense, I would be much more comfortable if it was uniformly -1.0 to make them flush!]

UPDATE I:

I think I found why my application behaves differently in the example test. I used code NSBezelStyle.RoundedBezelStyle

in code and set its height to 24.0; various things indicate this style / type of button to have a fixed height (see IB where the height parameter is grayed out and fixed at 21.0 and cannot be changed!) The difference between 24 and 21 is 3.0, which is exactly the fact that we can see this difference in the basic limitations of the application -4.0 in relation to the example of rest -1.0

Moral of the story: Don't use RoundedBezelStyle

outside certain use cases where variable height is needed! PostScript: RoundedRectBezelStyle seems to suffer from the same disease!

This still leaves the question of why some of the buttons in the test case do not match the -1.0 limit ...

UPDATE II:

Further testing shows that I get different results depending on which "type" of button I choose. In code, this will be associated with a property of the bezelStyle

button.

  • The gradient button is flush with the zero constraint between the buttons
  • Each texture button requires a +1.0 limit between buttons to avoid overlapping
  • Most other buttons (especially those with rounded borderless styles) seem to need a -1.0 limit between themselves in order to be flush.

REVISED QUESTION (based on my findings):

Are the above intentions of Apple (is there some logical / rational explanation) OR are they errors? If the above value is true, is it inappropriate to code my user interface (grid like a table) with these fudges for the inline "flash" how I compose my view?

+3


source to share


2 answers


How the presentation in terms of its boundaries depends on the presentation itself.



What you saw is the button style not spanning and then the whole frame set by the self-timer. This is the correct behavior.

+1


source


If this only happens with this button, then perhaps the button images have a small gap between the button and the edge of the image (for example, a place for a shadow shadow)



0


source







All Articles