"Fixed bug with binding to leading and final restrictions?

Here's another question that addresses a similar issue, but in this case, Xcode's behavior is correct, just annoying.

In my case, however, I think this is actually a bug:

example

This label can have an unlimited number of lines, so it will never be truncated, the text will simply break.

It works great with every localization:

example2

I want the label to be centered, and I want the text to be at least 20 pixels from the margins, so I set fixed limits for the leading and the ending. Xcode wants me to change one of them to a greater than or equal to restriction, but in this case the text will not be fully centered (I tried).

All I want is centered text, which will not be too close to the margins, but now I can not do this without triggering this warning.

Any ideas on how to fix this? Is this really a mistake, or am I doing something wrong?


Edit: Here is a screenshot showing the error. Constraints are not directly in the view controller, but in the subzone that I use as backgroun to represent the table. If I remove these restrictions, the warning disappears; if I add them, it will appear again. I tried this in a new project and could not reproduce it, I have no idea why this is happening here.

example3

Edit:

Here is another example. When the correct limit is set to "greater than or equal to" everything is fine:

example4

As soon as I set it equal, the arrow:

example5

+7
source share
3 answers

If you are still looking for an answer, in your particular case, try setting the proportional width on your label and centered horizontally in the view controller's view.

Remove all restrictions on the label, right-click and drag from the label to the Background View and select Equal Widths , Center Horizontally in Container and Center Vertically in Container from the pop-up menu.

Now that you say you want a 20px marker both to the left and to the right of your shortcut, edit Multiplier to limit the equal width and set it to widthOfBackgroundView - 40)/widthOfBackgroundView .

So let's say the width of your background view is 414 , the multiplier should be 374/414 .

The reason for the width minus 40 multiplier is a 20px coverage on either side of the label. This should make your warning go away and place the label as you expect.

I had the same problem and I was able to fix the warnings this way. Hope this helps!

+4
source

Some problem here introduced in the final version of Xcode 9. It seems that the error is related to the direction of the language: for some reason, Interface Builder does not very well understand the automatic markup for the conditions of the direction of the language by default.

As suggested by Repose in this thread, you should try to invalidate the use of the language direction for at least one of the unfulfilled restrictions (i.e., for trailing). This approach resolved my warnings.

+3
source

Tested in Xcode 9GM (version 9.0 (9A235)), works correctly

Xcode screenshot

Remove the restrictions and add them manually.

+2
source

Source: https://habr.com/ru/post/1271814/


All Articles