Xcode 9 - "Fixed Width Constraints May Cause Clipping" and Other Localization Warnings

Viewed 64613

I downloaded the new Xcode and in Interface Builder I'm having a ton of problems with warnings that say things like:

Fixed Width Constraints May Cause Clipping

It looks like this:

enter image description here

I do have localization for several languages and I understand the warning that in another language a label's size may change, but my app doesn't have this problem. I ran and tested it in Xcode 8 yesterday, it was fine. I don't want to spend hours and hours adding pointless new constraints.

Any suggested solutions?

13 Answers

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

enter image description here

Another quick solution !

For a UIButton by changing the title from plain to Attributed text also resolved my issue:-

enter image description here

I know 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 constraint this worked pretty well and was less effort, and I managed to keep the same output and adapt my view for the different devices.

Swift 4 , Xcode 9.1 :

About this issue, I think your object don't know what it's the correct center position in the context of it's superview, and using remove, greater than or other leading/trealing settings most of times don't work correctly. First, you must check the correct constraints of your superview.

If your superview/s are correctly setted, you can try to "explain" to your object what is the correct position in the view by setting the "horizontally in Container" constraint:

enter image description here

If you need fixed width constraint for button just set width constraint priority to 700.

I had the same problem, but when I changing to >= it automatically set the constant to 0, if I choose 60 for instance, the warning appears again. So I was in a loop with the problem.

I could fix embedding my Label in a View

Editor > Embed In > View

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

constraints

In View I set the constraints that I was expecting before.

I had the same problem when moving to Xcode 9 and found an approach that's useful for certain kinds of layouts. In my case, I wanted a table header in which two columns (UILabels) were of fixed width and another was of variable width. Regardless of how I specified column widths (including using constraints greater than or equal instead of equal, etc.), I kept getting the warning about possible clipping. In my case, I wanted the variable width column (UILabel) to clip if necessary. I could have just ignored the warning, but don't like doing that.

The approach that worked here was to create a UIView with appropriate size constraints and embed the UILabel as a subview in the UIView. Then truncation happens if necessary and I get no warning. This works whether the UIView/embedded UILabel is in a StackView or not.

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

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

enter image description here

To Fix The Error: Fixed Width Constraints May Cause Clipping” and Other Localization You need to select the view/object, go to the "Show Size Inspector", find the Width Constraint and set the Constant to Greater or Equal to:

Size Inspector

To Fix The Error: Leading/Trailing constraint is missing which may cause overlapping with other views

This means that the view/object Xcode is complaining about, is missing a Leading or Trailing Constraint to a neighboring view.

While holding control, drag to a near by view/object

Contrl + PressClick

Add a Leading or Trailing Constraint

Leading/Trailing Constraint

Related