Frage

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?

War es hilfreich?

Lösung

If you are using Interface builder to create & set position of your view, Select your View & do as the screenshot suggests below.

enter image description here

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:

  1. Height
  2. Width
  3. Distance from top/bottom layout guide/view.

Let me know if you don't know how to do this.

Andere Tipps

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

enter image description here

output portait

enter image description here

output landscape

enter image description here

in your xib ,you should add 3 constraints :

  1. Hirizontal Center in Container;
  2. Width ;
  3. Height ;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top