我用Xcode6 beta6打开了一个现有的iOS项目,Xcode列出了以下对Storyboard和Xib文件的警告:
自动首选最大布局宽度在iOS版本中不可用 8.0以前版本
我尝试通过设置宽度来解决警告,如下所示:
然而,这并没有消除警告。如何去除?
我用Xcode6 beta6打开了一个现有的iOS项目,Xcode列出了以下对Storyboard和Xib文件的警告:
自动首选最大布局宽度在iOS版本中不可用 8.0以前版本
我尝试通过设置宽度来解决警告,如下所示:
然而,这并没有消除警告。如何去除?
当前回答
更新3: 如果部署目标设置为7.1,那么numberolines设置为1以外的任何值的标签也可能触发此警告。这是完全可复制的与新的单视图项目。
复制步骤:
创建一个新的单视图objective-c项目 将部署目标设置为7.1 打开项目的故事板 将标签放到所提供的视图控制器上 将该标签的numberolines设置为2。 编译
我已经提交了以下雷达: rdar: / /问题/ 18700567
更新2: 不幸的是,在Xcode 6的发行版中又出现了这种情况。请注意,在大多数情况下,您可以手动编辑故事板/xib来修复这个问题。以下是查尔斯·a的评论:
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.
更新1: 这个错误现在已经在Xcode 6 GM中修复。
原来的答案 这是Xcode6-Beta6和XCode6-Beta7中的一个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.
或者,你可以通过使用故事板或xib上的文件检查器来解决这个问题,并将“用于”更改为“用于iOS 8.0及以后版本的构建”
其他回答
出于某种原因,即使将iOS部署目标更改为8.0或更高版本,Xib文件也不会采用该更改,并在文件检查器中保持先前的设置
因此,您应该为每个Xib手动更改它
一旦完成,警告将消失:-)
总而言之,对于我来说,按照上面的两条指令来更改numberOfLines = 0为1或更大的任何实例,并手动将preferredmaxlayoutidth ="0"添加到故事板源代码中的每个标签实例中,可以修复我的所有警告。
解决方法很简单
只需要启用iOS 8及更高版本的构建即可
更新3: 如果部署目标设置为7.1,那么numberolines设置为1以外的任何值的标签也可能触发此警告。这是完全可复制的与新的单视图项目。
复制步骤:
创建一个新的单视图objective-c项目 将部署目标设置为7.1 打开项目的故事板 将标签放到所提供的视图控制器上 将该标签的numberolines设置为2。 编译
我已经提交了以下雷达: rdar: / /问题/ 18700567
更新2: 不幸的是,在Xcode 6的发行版中又出现了这种情况。请注意,在大多数情况下,您可以手动编辑故事板/xib来修复这个问题。以下是查尔斯·a的评论:
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.
更新1: 这个错误现在已经在Xcode 6 GM中修复。
原来的答案 这是Xcode6-Beta6和XCode6-Beta7中的一个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.
或者,你可以通过使用故事板或xib上的文件检查器来解决这个问题,并将“用于”更改为“用于iOS 8.0及以后版本的构建”
您可以在不将故事板作为源打开的情况下修复此问题。 如果numberolines !=1并且部署目标< 8.0,UILabels将触发此警告
如何找到它?
转到Issue Navigator (CMD+8)并选择带有警告的最新构建 找到警告(s)(搜索“自动首选最大布局”)并按下右边的展开按钮 找到UILabel的对象ID 打开Storyboard并搜索(CMD+f)对象。它将选择并突出显示UILabel 根据其他人的建议,设置Preferred Width = 0 "Explicit"