Xcode 9 - “Fixed Width Constraints May Crop” and other localization warnings

I downloaded the new Xcode in Interface Builder too. I have many problems with warnings that say things like:

Fixed Width Constraints May Crop

It looks like this:

enter image description here

I have localization for several languages, and I understand the warning that in another language the label size may change, but my application does not have this problem. I ran and tested it in Xcode 8 yesterday, everything was in order. I do not want to spend hours and hours adding meaningless new restrictions.

Any suggested solutions?

+128
ios interface-builder localization xcode9-beta
Jul 15 '17 at 21:01
source share
14 answers

I received the same warnings even without several languages ​​in my application , which made me find out what was really happening.,.

There are several different things going on here. I was able to turn off fixed-width alerts in my application by changing the width of the distances between objects from a fixed-width to greater than or equal to or less than or equal to .

This can be done by selecting an object in the interface builder, going to the size inspector and changing it there:

enter image description here




Or select a constraint from the outline of the document, go to the size inspector and change it there:

enter image description here







As for the warning at the top of the screenshot:

Fixed main and final constraints with a central constraint to cause clipping

Here is a screenshot from my own application in which I received the same warning:

enter image description here

I had a label with the @ icon set to the beginning and end of the buttons, but also to align the center with the rating label . When I removed the center alignment constraint , the warning disappeared, but I was left with the wrong set of objects.

Then I put up with hugging Stack View . How annoying, since it needs to be used, when you get all the restrictions and settings to the right, it’s fine and without warning.




Edit

As Hold is written in a comment, sometimes just adding> = 0 will be what you need, as you make sure that the two elements do not overlap.

+155
Aug 18 '17 at 22:43 on
source share
— -

You can try disabling "Respect Language Direction" for each constraint to disable the warning and see if it helps. Select your limit and open Attributes / Size Inspector. Please see the image attached.

If you do not plan to localize your application in other languages, this solution should not have any fallback options. For localized applications, you should be more careful about the size of the shortcut and font.

PS This solution works for iOS. For macOS, try> = or <= to turn off the warning.

pps The shortcuts in the figure below are much easier to create using the AutoLayout and attribuStString properties for a single UILabel or UITextView using NSMutableAttributedString. Image is for demonstration purposes only.

Disrespect Language Direction

+55
Aug 18 '17 at 20:02 on
source share

For localized labels and buttons, this warning makes sense, and you must provide the necessary restrictions so that your labels do not overlap. If they do not intersect now, they may in the future, so it will not hurt to provide restrictions.

Xcode helps you automatically add these restrictions:

In the document layout of your storyboard, click on the yellow arrow and select "fixed start" or "fixed trailing", depending on where the text is on your screen (left or right). This will fix most problems.

Xcode screenshot

If you have this problem with a button with no text (image only), try removing the "default title" that can still be set for the button:

Xcode screenshot

+27
Sep 16 '17 at 14:16
source share

With Labels you can set the Lines is 0 and Autoshrink properties of the Minimum Font Size to remove the Fixed Width Constraints May Cause Clipping warnings, for example:

enter image description here

+25
Oct 04 '17 at 3:25
source share

Another quick fix!

For UIButton, changing the title from normal to attribute text also solved my problem:

enter image description here

+12
Jul 25 '18 at 4:59
source share

Swift 4, Xcode 9.1:

About this problem, I think that your object does not know what its correct central position is in the context of this supervisor , and most of the time it deletes more or other control parameters / do not work correctly. First, you must check the correct limitations of your supervisor.

If your supervisor / s is configured correctly, you can try to “explain” to your object what the correct position is in the view by setting the restriction “horizontally in the container” :

enter image description here

+4
Nov 15 '17 at 10:45
source share

I know that this question has already been answered, but what I did to fix this error, in my case, was to add the "Aspect Ratio" property, and then eliminate the width or height restriction, which turned out very well , and there was less effort, and I managed to keep the same result and adapt my view for different devices.

+4
Jan 18 '18 at 4:50
source share

I had the same problem, but when I go to >= , it automatically sets the constant to 0 if I select 60 , for example, a warning appears again. So I was in a loop with the problem.

I could fix the embedding of my Label in the View

 Editor > Embed In > View 

In Label I set Top , Bottom , Leading and Trailing with constant = 0

limitations

In View I set the constraints that I had expected before.

+1
Nov 14 '17 at 16:45
source share

I had the same problem when migrating to Xcode 9 and an approach was found that is useful for certain types of layouts. In my case, I need a table heading in which two columns (UILabels) have a fixed width and the other a variable width. No matter how I set the width of the columns (including the use of constraints greater than or equal to, not equal, etc.), I continued to receive a warning about a possible clipping. In my case, I wanted the variable width column (UILabel) to be copied if necessary. I could just ignore this warning, but I don't like to do it.

The approach that worked here was to create a UIView with appropriate size restrictions and embed UILabel as a subset in the UIView. Then, if necessary, truncation occurs, and I do not receive a warning. This works whether the UIView / embedded UILabel is in the StackView or not.

This is essentially the same approach as Haroldo Gondim, but here you can see that it also works with or without StackView.

The following figure shows the approach, with and without StackView. "SpacerName" is the variable width of the UIView containing the label, and "SpacerPD" is the number with a fixed width of 80. [Colors are not significant; just to show where the views are.]

enter image description here

+1
Jan 12 '18 at 21:19
source share

If you need a fixed width limit for a button, just set the priority of the width limit to 700 .

+1
Apr 08 '19 at 13:48
source share

As you can see in the image below, I had the error “Fixed width limits that could cause cropping,” because although I found that the text box was vertically centered and my shortcut has a left margin, I didn't have determined the restriction for the text field relative to the label, so Xcode warned me that the text field could pin (will be displayed above) the label.

enter image description here

After adding a left constraint to the text box to always stay at some distance from the label, the error was considered resolved by Xcode and it no longer bothered me with warning the constraint.

0
Mar 03 '18 at 23:05
source share

I had a similar problem when trying a button with the same paddings with the edges of the super view.

Error case

As a result, I used the horizontal center and equal widths for super view .

My decision

0
Mar 28 '18 at 3:17
source share

To fix the error : fixed width limits can lead to clipping and other localization. You need to select the view / object, go to “Show size inspector”, find the width limit and set the constant to “greater” or “equal”:

Size inspector

Bug Fix : Leading / Trailing constraint is missing, which may lead to overlapping with other views

This means that the Xcode of the view / object complained of skips the leading or trailing constraint for the neighboring view.

While holding the control, drag to the closest view / object

Contrl + PressClick

Add Lead or End Constraint

Leading / Trailing Constraint

0
Sep 15 '18 at 16:56
source share

For UIButton, if you are GOOD in design to crop the text, use this option to disable the warning:

enter image description here

0
Feb 01 '19 at 9:08
source share



All Articles