i have set a subview in a view controller, in which there is a button i have set constraints of that subview and preview it on different screens it looks fine in preview but when i run on different screen it changes the position . The subview is on the bottom left of the view controller. The constraints i have used are,
Asked
Active
Viewed 84 times
0

Anbu.Karthik
- 82,064
- 23
- 174
- 143

Oneeb
- 75
- 1
- 1
- 9
-
If you want to keep it at the bottom left of the view controller then you need only four constraints: leading, bottom, height, width. It will stick there only. – Amit Aug 26 '17 at 10:55
-
have u seen the screen shots? @Amit – Oneeb Aug 26 '17 at 10:56
-
hey Oneeb, you need to set a relative height constraint and aspect ratio as 1:1 instead of a fixed height, width constraints. Otherwise, in smaller screens the button will overlap – Jen Jose Aug 26 '17 at 11:01
-
i have used all these constraints but when i test it on real device it comes above the button i don't know why. @Amit – Oneeb Aug 26 '17 at 11:01
-
The constraints that you have added will design the UI look good on 6 and 6s, but for 5s you have to make the UI scrollable. – Amit Aug 26 '17 at 11:02
-
How to set the all that as u described above? @JenJose – Oneeb Aug 26 '17 at 11:03
-
can't we give one time constraints so that it can adjust on all screens? @Amit – Oneeb Aug 26 '17 at 11:08
-
@JenJose is right. For you query , don't set fixed height to buttons and views, use aspect ratio. – Amit Aug 26 '17 at 11:17
-
how to set relative height than? @Amit – Oneeb Aug 26 '17 at 11:25
-
@Oneeb , you need to read more on relative size constraints. Thats easy, the key is instead of constant, we use multiplier. Now for your design, you need to set a relative constraint for top Image, then in a fixed height view you will place the three buttons and layout it on the screen and for the bottom-left button you will use a relative height-width. Simple! – Jen Jose Aug 26 '17 at 11:48
-
have u have any link that can simply explain the concept of relative size. @JenJose – Oneeb Aug 26 '17 at 12:03
-
Check this for relative proportional size constraints https://www.raywenderlich.com/162311/adaptive-layout-tutorial-ios-11-getting-started and for relative positioning check https://stackoverflow.com/questions/27882717/ios-proportional-spacing-with-autolayout (which is based on center constraints and same can be done with BottomLayout constraint) . start with these, you will gradually pick up other tricks.. – Jen Jose Aug 26 '17 at 12:28
-
Thanks i will follow this. @JenJose – Oneeb Aug 26 '17 at 12:50
1 Answers
0
There are different approach for this programmatically and using storyboard.
I have implemented this in my project using storyboard with the help of these links:
- Xcode AutoLayout, Make Margin proportional with height
- autolayout - make height of view relative to half superview height
Please check if it helps in your scenario.

Amit
- 4,837
- 5
- 31
- 46