Automatic Preferred Max Layout Width Is Not Available on iOS Versions Prior to 8.0

Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

Update 3:

This warning can also be triggered by labels that have numberOfLines set to anything but 1 if your deployment target is set to 7.1. This is completely reproducible with new single-view project.

Steps to Reproduce:

  1. Create a new single-view, objective-c project
  2. Set the Deployment Target to 7.1
  3. Open the project's storyboard
  4. Drop a label onto the provided view controller
  5. Set the numberOfLines for that label to 2.
  6. Compile

I've filed the following radar:

rdar://problem/18700567

Update 2:

Unfortunately, this is a thing again in the release version of Xcode 6. Note that you can, for the most part, manually edit your storyboard/xib to fix the problem. Per Charles A. in the comments below:

It's worth mentioning that you can pretty easily accidentally
introduce this warning, and the warning itself doesn't help in finding
the label that is the culprit. This is unfortunate in a complex
storyboard. You can open the storyboard as a source file and search
with the regex to find labels that
omit a preferredMaxLayoutWidth attribute/value. If you add in
preferredMaxLayoutWidth="0" on such lines, it is the same as marking
explicit and setting the value 0.

Update 1:

This bug has now been fixed in Xcode 6 GM.

Original Answer

This is a bug in Xcode6-Beta6 and XCode6-Beta7 and can be safely ignored for now.

An Apple engineer in the Apple Developer forums had this to say about the bug:

Preferred max layout width is an auto layout property on UILabel that
allows it to automatically grow vertically to fit its content.
Versions of Xcode prior to 6.0 would set preferredMaxLayoutWidth for
multiline labels to the current bounds size at design time. You would
need to manually update preferredMaxLayoutWidth at runtime if your
horizontal layout changed.

iOS 8 added support for automatically computing
preferredMaxLayoutWidth at runtime, which makes creating multiline
labels even easier. This setting is not backwards compatible with iOS
7. To support both iOS 7 and iOS 8, Xcode 6 allows you to pick either "Automatic" or "Explicit" for preferredMaxLayoutWidth in the size
inspector. You should:

Pick "Automatic" if targeting iOS 8 for the best experience. Pick
"Explicit" if targeting < iOS 8. You can then enter the value of
preferredMaxLayoutWidth you would like set. Enabling "Explicit"
defaults to the current bounds size at the time you checked the box.

The warning will appear if (1) you're using auto layout, (2)
"Automatic" is set for a multiline label [you can check this in the
size inspector for the label], and (3) your deployment target < iOS 8.

It seems the bug is that this warning appears for non-autolayout
documents. If you are seeing this warning and not using auto layout
you can ignore the warning.

Alternately, you can work around the issue by using the file inspector on the storyboard or xib in question and change "Builds for" to "Builds for iOS 8.0 and Later"
Xcode file inspector

Finding cause of Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

Here is one way to find the specific label that is causing this warning:

  1. Right click on the warning and choose "Reveal in Log"
  2. The warning in the log will be highlighted. Copy the interface builder object ID for this label (it looks like xxx-xx-xxx).
  3. Paste this in the Find Navigator. When you click on this result it will open the interface builder with the offending label selected.

automatic preferred max layout width before ios 8.0 in Xcode 7

This is a warning related to label's Width property. We need to check "Explicit" for label's width.

Attribute Unavailable: First baseline layout attribute on iOS versions prior to 8.0

Found the issue. This new constraint was added to iOS 8.0 and isn't supported with previous versions.

To get rid of this warning and allow iOS 7 builds to work you need to:

1. Click on the warning in the side bar (this should highlight the offending constraint)

2. Change that constraint to something other than "First Baseline". "Center Y" worked well for me. You'll have to play with the options and can see the changes live to see which alternative works for you.

iOS 7 now builds again and warning is gone.

Sample Image

Layout attributes relative to the layout margin on iOS versions prior to 8.0

Disable "Prefer margin relative"

Sample Image

Attribute Unavailable warning on iOS versions prior to 8.0

Since I had already created the constraints, the answer was to click on the constraint, and then look in the Utilities bar (on the right). As shown in the picture below, click on an item and then make sure that "relative to margin" is unchecked.

Relative to margin screenshot



Related Topics



Leave a reply



Submit