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

转载 2015年07月10日 00:42:14
up vote293down voteaccepted

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 <label(?!.*preferredMaxLayoutWidth) 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

shareimprove this answer
 
11  
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<label(?!.*preferredMaxLayoutWidth) to find labels that omit a preferredMaxLayoutWidthattribute/value. If you add in preferredMaxLayoutWidth="0" on such lines, it is the same as marking explicit and setting the value 0. –  Charles A. Oct 17 '14 at 1:31 
1  
Is there any way programatically to configure a UILabel to automatically adjust preferredMaxLayoutWidth, without actually subclassing it or implementing it somewhere in layoutSubviews? If this is a behavior that IB can enable, that suggests there's a property or magic value that can be set. But nothing in the API docs or headers says that. –  algal Oct 17 '14 at 23:32
1  
@CharlesA. I've been testing with an empty project and found another label attribute that will trigger this warning: if numberOfLines is set to anything but 1, the warning will happen regardless of if you havepreferredMaxLayoutWidth set or not. –  memmons Oct 18 '14 at 15:44
2  
@MichaelG.Emmons Strange, I cannot reproduce this with a clean project and a deployment target set to 7.1. Once I set the preferredMaxLayoutWidth to an explicit 0 the warning goes away regardless of thenumberOfLines value. But perhaps this was fixed in the Xcode update this morning? –  Charles A. Oct 21 '14 at 18:01 
1  
Using Xcode 6.1 and Swift, I can tell you that the last solution, which is: " 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" " works like a charm for me. –  King-Wizard Dec 23 '14 at 20:02

iOS8.0 之后UIAlertView和UIActionSheet的创建方式的新变化

最近已经换了Xcode 6.1,开始适配I欧
  • huxiaoqiao163
  • huxiaoqiao163
  • 2014年11月06日 17:44
  • 1125

可用性 available 简析

available Swift有两种属性,分别为适用于声明和适用于类型的属性。available属于声明属性. 将 available 用于声明时,表示该声明的生命周期与特定的...
  • jancywen
  • jancywen
  • 2017年05月19日 11:02
  • 1221

IOS9 适配注意事项

转自https://github.com/ChenYilong/iOS9AdaptationTips 作者 微博@iOS程序犭袁 iOS9适配系列教程【中文在页面下方】 (截至...
  • work4blue
  • work4blue
  • 2015年09月24日 15:39
  • 4479

HttpClient 4.3连接池参数配置及源码解读_0

目前所在公司使用HttpClient 4.3.3版本发送Rest请求,调用接口。最近出现了调用查询接口服务慢的生产问题,在排查整个调用链可能存在的问题时(从客户端发起Http请求->ESB->服务端处...
  • xjr56807
  • xjr56807
  • 2017年02月05日 16:48
  • 373

IOS应用开发版本控制工具之Versions 和SVN 的 使用方法详解

http://ytwhw.iteye.com/blog/1753954 Versions版本控制工具破解版(Versions.zip)下载请见本博文附件。下载后在MAC安装完以后,图标是莲花状...
  • jeffasd
  • jeffasd
  • 2016年01月13日 14:53
  • 8573

IOS开发~OC有用的小知识点

1、获取系统语言设置      NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];      NSAr...
  • fly601845
  • fly601845
  • 2015年02月07日 11:45
  • 1208

iOS10适配问题

随着iOS10发布的临近,大家的App都需要适配iOS10,下面是我总结的一些关于iOS10适配方面的问题,如果有错误,欢迎指出. 1.系统判断方法失效: 在你的项目中,当需要判断系统版本的话,不...
  • ZH952016281
  • ZH952016281
  • 2016年09月14日 13:08
  • 8171

mac下的svn工具——Versions使用详解

在mac下开发有几种常用的svn工具:Xcode自带的,Git,Versions等。       Git我只下过代码,还没用来托管过代码。Xcode自带的svn工具用过几天,不是很习惯。个人偏向于V...
  • sjx19871225
  • sjx19871225
  • 2013年04月03日 10:47
  • 14456

MDS中file layout初始化过程

pNFS系统的部署过程见这篇文章:http://blog.csdn.net/ycnian/article/details/8523193。这篇文章中我们讲讲MDS的初始化过程,主要想讲讲向文件/pro...
  • ycnian
  • ycnian
  • 2013年03月31日 15:58
  • 1566

app advice:苹果iOS 2.0 – iOS 8.0各版本发布时间表

http://www.199it.com/archives/255587.html app advice:苹果iOS 2.0 – iOS 8.0各版本发布时间表 ...
  • u011537073
  • u011537073
  • 2016年04月22日 22:29
  • 803
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
举报原因:
原因补充:

(最多只允许输入30个字)