警告:Automatic Preferred Max Layout Width before iOS8.0
来源:互联网 发布:恺英网络联系方式 编辑:程序博客网 时间:2024/04/28 03:12
警告
项目中有时会出现这个警告”Automatic Preferred Max Layout Width before iOS8.0”,一般是在项目的xib文件(或storyboard中),这是Label的一个属性导致的. 而且, 一般是在 xib文件中有自适应的 label 才能导致的, 是与 iOS6兼容的错误.
原因
对应的属性为preferredMaxLayoutWidth,这个属性的作用如下:
This property affects the size of the label when layout constraints are applied to it. During layout, if the text extends beyond the width specified by this property, the additional text is flowed to one or more new lines, thereby increasing the height of the label.
其实也就是自动换行的最大宽度.
对于单行的label,这个属性不用设置,无效.(但是需要注意,在xib中,当项目部署版本为7.0的话,为了解决警告,依旧需要点选Explicit).
出现这个警告的原因一般是因为项目的部署版本为7.0,但是label又没有勾选Explicit导致的,警告的意思即自动偏好宽度在8.0以前不适用,因此对于部署在7.0的项目,应该勾选.
那么,里面的数值怎么设置?
一般来说,勾选的时候,会自动设置一个宽度,这个宽度是label当前在xib中的宽度,对于多行label(行数大于1,或者行数设置为0),意思即当label中的文字宽度大于这个宽度的时候,label会换行.
那么,问题来了,对于使用了AutoLayout的label,宽度在不同屏幕上是不一样的,那么这个换行的最大宽度怎么设置?
解决方案
方案一
按照最小屏幕宽度的 iphone4 来计算, 然后进行约束就可以了. 因为不会影响在 6和6p上的换行. 运行效果如下图,只有在到达约束的限制距离时 才会启动换行.
如果想设置约束为距离屏幕左右各为10的距离,运行在iPhone4s 上设为屏幕的宽320减去边距左右各10 , 所以Preferred Width(自动换行最大宽度) 设置为300 .
方案二
如果你知道一个确切的width当然是最好的,就可以按照最小屏幕宽度的 iphone4 来计算, 然后进行约束。
但是如果UILabel的宽度是自适应的,不确定,那么可以使用如下的代码设置:
- (void)layoutSubViews{ [super layoutSubViews]; self.label.preferredMaxLayoutWidth = self.label.bounds.size.width;}
当label已经显示到界面上的时候,那么宽度就已经确定了,可以直接用此宽度作为最大autolayout宽度设置。这样就正常了
推荐文章: 警告:Attribute Unavailable Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- 警告:Automatic Preferred Max Layout Width before iOS8.0
- Automatic Preferred Max Layout Width before iOS8.0 解决探索
- automatic preferred max layout width警告
- iOS自动布局解决警告Automatic Preferred Max Layout Width before iOS 8.0
- warning: Automatic Preferred Max Layout Width before iOS 8.0
- Automatic Preferred Max Layout Width before iOS 8.0解决办法
- 警告:Attribute Unavailable Automatic Preferred Max Layout Width is not available on iOS versions pri
- Automatic Preferred Max Layout Width is not available on
- iOS自动布局解决警告Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- iOS自动布局解决警告Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- 【Tip来1发】去除Preferred Max Layout Width警告
- 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
- Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior t
- Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior t
- Attribute Unavailable: Automatic Preferred Max Layout Width is not available on iOS versions prior t
- Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- [Xcode] Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0
- HDFS源码分析数据块汇报之损坏数据块检测checkReplicaCorrupt()
- IntelliJ Idea编译报错:请使用 -source 7 或更高版本以启用 diamond 运算符
- hdu 5444 Elven Postman(长春网路赛——平衡二叉树遍历)
- yarn
- 教你怎么用键盘
- 警告:Automatic Preferred Max Layout Width before iOS8.0
- Dism 错误 87
- 点击按钮切换横竖屏
- sublime text3保存时自动删除底部空格
- FZU 2089 数字游戏
- 邻接表的spfa
- 汉诺塔问题(java实现)
- Android应用控制LED(静态编译LED驱动)
- dbms_output.enable()有什么用