问题
How do you use Autolayout to make a UI Element centered left-to-right when in both landscape and portrait mode? Can you have variables in autolayout?
回答1:
If you are using Interface builder to create & set position of your view, Select your View & do as the screenshot suggests below.
After that, click on "Add constraint" & you are done. This is just to set your view in horizontal centre. But you have to still add some more constraints. They are:
- Height
- Width
- Distance from top/bottom layout guide/view.
Let me know if you don't know how to do this.
回答2:
set constraints both vertical and horizontal
more understand autolayout easily follow this link
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
output portait
output landscape
回答3:
in your xib ,you should add 3 constraints :
- Hirizontal Center in Container;
- Width ;
- Height ;
来源:https://stackoverflow.com/questions/21793542/center-ui-elements-in-view-with-autolayout