问题描述
我有原型的tableview细胞,与细胞的tableview内的自定义视图。包含的tableview视图控制器将只显示在横向模式。我们的目标是为是的tableview细胞内来调整它的基础上,外形宽度的UIView。因此,例如,有可能是在左边和右边,然后UIView的重新调整它的宽度,以填补空间的其余部分20pt间距。我希望用故事板和自动布局做到这一点。
I have a prototype tableview cell, with a custom view inside of the tableview cell. The view controller that contains the tableview will only be displayed in landscape mode. The goal is for the UIView that is inside of the tableview cell to resize it's width based on the form factor. So for example there might be a 20pt spacing on the left and right and then the uiview resizes it's width to fill the rest of the space. I'm hoping to do this with storyboard and autolayout.
在3.5英寸外形看起来像这样(这是它应该是什么样子的4英寸的方式为好)
In 3.5 inch form factor it looks like this (this is what it should look like in 4 inch mode as well)
在4英寸外形看起来像这样(宽度没有自动调整)
In 4 inch form factor it looks like this (width didn't auto resize)
据我了解,自动布局这里是合法的,由于水平空间> 20的4英寸规格的为好。这个问题虽然是...我怎么得到一个子视图自动调整它的宽度的心脏时的屏幕变化使用情节提要/自动版式/限制宽度?
I understand that the 'auto layout' here is legal, since the horizontal space is >20 on the 4 inch form factor as well. The heart of the question though is... how do I get a subview to autoresize it's width when the width of the screen changes using storyboard/autolayout/constraints?
推荐答案
所有你需要的是以下四个约束来自动调整大小的单元格视图3.5 4英寸屏幕。
All you need are following four constraints to autosize your cell view for 3.5 and 4 inches screens.
X $ C $ç4.6 界面生成器
具有这样有时不能正确3.5之间切换的ViewController大小时,应用约束和4在设计时的错误。然而,在3.5和4个仿真器打开时,它工作得很好。
Xcode 4.6 Interface Builder
has a bug where at times it does not properly apply constraints when switching ViewController size between 3.5" and 4" at design time. However, it works just fine when opened in the 3.5" and 4" simulators.
这篇关于调整3.5和4英寸外形的看法与自动布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!