Resize view with Auto Layout between 3.5 and 4 inch form factor

爷,独闯天下 提交于 2019-12-22 10:39:35

问题


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.

In 3.5 inch form factor it looks like this (this is what it should look like in 4 inch mode as well)

In 4 inch form factor it looks like this (width didn't auto resize)

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?


回答1:


All you need are following four constraints to autosize your cell view for 3.5 and 4 inches screens.

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.



来源:https://stackoverflow.com/questions/18862476/resize-view-with-auto-layout-between-3-5-and-4-inch-form-factor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!