XCode 9 fixed width constraints may cause clipping

I am getting a new warning in XCode 9 that says "xcode 9 fixed width constraints may cause clipping". I intentionally have fixed with constraints on buttons with icons and text where I am using an icon font. In both these cases localization will not change the text thus causing clipping. Is there a way to turn this warning off? It would be nice to turn it off just for items that I have explicitly decided it needs a fixed width but I'm willing to turn it off all the time. I don't want to turn off all warnings in the storyboard because some of them are useful.


Also, XCode 9 beta 5 seems to be compiling the entire project over and over again every time I build. It does this even as I'm typing and slows down simple coding tasks.

Do you get any problem at runtime ?


In XCode7 or 8, I have several alerts "view is clipping its content" that I could not get rid of.

My guess is that it's not warning that the items might clip their contents (e.g. if localization would make a string longer), but that fixed-wdith items may be clipped by their containers, if those containers can get resized (e.g. for different display sizes).


Is there a downside in making these items size relative to their containers? Assuming they actually fit on any actual display size, it shouldn't matter if they layout wider than intended.


If your use case makes this impractical, I'd suggest you submit a bug report explaining the scenario. Adding "useful" warnings in Xcode is great, unless they overlook a valid use case, so the Xcode development team should be told about it.

I have the same problem.


197 warnings to say "Fixed width constraint may cause clipping" for all my labels.


I do not have fixed width ?


Help!

These are indeed annoying. In many cases, they make no sense at all. For example, I have set a segmented control with fixed width and it doesn't display any text, just icons. And, there is a large amount of space around the artwork.


I'll be filing a bug about this as there should be a way to relax that warning. Or, perhaps better, have the ability to mark a view (would be an IB-only piece of data) as being OK.


As it stands, I have to constantly look to see if they are the same warnings, or if I have new legitimate warnings.

>> there is a large amount of space around the artwork


This is the wrong way to reason about the layout. The amount of space depends on the container's size, and the container's size in IB has no direct relationship to the container's size at runtime.


It's also a poor assumption to assign a fixed width to a button or segmented control that doesn't have text. Future changes to standard control appearance might change the size of the "chrome", or change the way the icon is scaled within the control. That could cause clipping too. A flexible trailing edge constraint (see below) might be a better choice than a fixed width constraint.


>> have the ability to mark a view (would be an IB-only piece of data) as being OK


Did you try having IB fix the error? If you go into the constraint error detail view (click the tiny orange arrow icon beside the view in the view hierarchy), then the view hierarchy is replaced by a list of layout errors. In most cases, beside each error is a fix-it button. Try clicking one of those, choose an option, and see what constraint that generates.


You should also be able to apply multiple fix-its using the popup menu on the last autolayout icon at the bottom of the canvas.


In my case, I wasn't getting a fixed width warning, but a warning saying that the trailing edge was unconstrained. The fix-it added a ">= 0" constraint to the superview's trailing edge.

No, it's not the wrong way. Some of my segmented controls show simple icons (for the basic math symbols). If left to render based on content, the segmented controls size is much too narrow. I stretched the control wider to a fixed width to work well on all size classes.

The warning in this case mentions that the segmented control may not work with localized text. Of course I get that. In other areas of the app, I do the proper thing (app is in nine languages).

Forcing folks to add extra contraints for no benefit is not a good thing. Hence there should be a way to silence the warning as these are definitely more subjective.

Sorry, I didn't intend to sound overly prescriptive. Of course you will decide to do whatever you decide to do.


However, for the sake of this discussion, I do think your reasoning is a little imperfect:


1. Your segment might be icons and not text, and the default warning may refer only to text as the most common case, but icons are in general localizable too. Basic math symbols may not be the same in all regions. You may know that you'll never localize for a region that requires different icons, but Xcode doesn't know that.


2. If your icons need sufficient space around their image, then it's probably better to design the space into the icon images, instead of trying to fudge the segment widths.


>> Forcing folks to add extra contraints for no benefit is not a good thing.


It's not obvious that there's no benefit. The warning results from a mathematical analysis of the actual constraints, and represents a likely problem (clipping) under some more or less probable mathematical conditions. If you supply the "missing" constraints, you get the confidence of knowing that your layout is less subject to breaking in the future. That's a benefit, even if a small one.


>> Hence there should be a way to silence the warning as these are definitely more subjective.


There is a way to silence the warning (on a case-by-case basis): add the missing constraint, which only takes a moment. In your particular case, a trailing ">= 0" alignment constraint should do it, because it tells the layout analysis that the containing view can't get smaller than the width. That is, in fact, your claim, isn't it — the containing view can't get that small?

I am also facing same warnings after xcode 9 update. I am not using any localization in my app, still getting those warnings. Please suggest if someone faced the same issue? Thanks 🙂

This warning is indeed annoying and there still seems to be no way to silence it (without silencing all Interface Builder warnings) in Xcode 11. I have a similiar related warning for not using autolayout constraints "views without layout constraints may clip their content".


I have a xib that does not use autolayout at all. This view uses manual layout...I know, I know, you want me to use autolayout but the view works just fine the way it is and I see no reason to start using autolayout just for the sake of using it.


I have a label with text that changes. After the text change I make a sizeToFit call. I don't need or want autolayout here. While I understand this warning may be useful in some cases for some xibs, there should be a way to disable it IMO.

Change your constraints with text on "greater than or equal". This warning means that if, for example, you will change the language of your text on another language it may require more space, so that "greater than or equal" constraint will help solve this problem.

XCode 9 fixed width constraints may cause clipping
 
 
Q