Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

position a view in storyboard at 1/3 of screen size

I'm trying to position a view in storyboard to always have it top edge at 1/3 of screen size. I have currently set a constraint to Top Layout Guide, but the constraint's constant is...well it is constant no matter which screen size it is used in, but I want it to be 1/3 of screen size. Can this be done entirely in storyboard? Thanks for answers

Screenshot of current state:

enter image description here

like image 248
potato Avatar asked Aug 19 '15 15:08

potato


People also ask

What is stack view?

Overview. Stack views let you leverage the power of Auto Layout, creating user interfaces that can dynamically adapt to the device's orientation, screen size, and any changes in the available space. The stack view manages the layout of all the views in its arrangedSubviews property.

How do you center a storyboard?

Select your button (or whatever view you want to center) on the storyboard. Then click the align button on the bottom right. Select Horizontally in Container and Vertically in Container .

What is Auto layout swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


Video Answer


2 Answers

Create a constraint between the view's top edge and the superview's bottom edge. Set the constraint's constant to zero, and set its multiplier to 1:3. Like this:

enter image description here

like image 165
Tamás Zahola Avatar answered Sep 18 '22 14:09

Tamás Zahola


You can setup it against center or bottom. Here is an example constraints related to center: (1/3 from top = 1.66 from center) contraints

like image 42
Danil Avatar answered Sep 17 '22 14:09

Danil