XCode自动布局Warning: Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

本文探讨了iOS中UILabel在不同版本下对于多行显示的支持情况。特别关注iOS8引入的自动计算preferredMaxLayoutWidth特性及其对iOS7及更早版本的影响。为确保良好的跨版本兼容性,建议开发者在使用多行UILabel时采取合适的设置。

解决方法参考 :  http://stackoverflow.com/questions/25398312/automatic-preferred-max-layout-width-is-not-available-on-ios-versions-prior-to-8

重点摘要: 

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.


 这里是说,如果label设置了1行,那么可以根据字符串需要自动计算最大宽度的,
如果设置了多行,iOS8及以上可以支持自动计算宽度,但是小于iOS8的就不支持了,所以如果要支持到iOS7,就要显式(Explicit)的明确写上label所支持的最大宽度。


所以,如果工程要支持iOS7.0, 在多行的label,要选择勾选explicit并写上允许的最大值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值