2

How can we put constraints like

  1. The vertical distance between two buttons must be '20 points' in the screen of height '568 points' and

  2. must be '25 points in the screen of height '667 points' ?

Kirsteins
  • 27,065
  • 8
  • 76
  • 78

2 Answers2

0

First of all get the screen height with this:

var bounds = UIScreen.mainScreen().bounds
var height = bounds.size.height

After that you can set constraint this way with height:

switch height {
    case 568:
        buttonSpecing.constant = 20
    case 667:
        buttonSpecing.constant = 25
    default:
        println("Not Found")
}

And you can create buttonSpecing outlet this way:

enter image description here

Hope this will help.

Community
  • 1
  • 1
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
0

I think you want the gap between the buttons dynamic for all device screens. Here is the way you can use to make this happen. i think you don't want to assign exact values for checking all devices every time. Take a UIView with alpha 0 and clear color and use it instead of the gap and use those constraints for the gap view.

1) Vertical spacing 0 between the top button and the gap view.

2) Vertical spacing 0 between the bottom button and the gap view.

3) Equal width to top or bottom button.

4) Center X to top button or bottom button.

5) Proportional Height to main view(you can add this constraint by adding equal height from subview to any of superview and then by changing the multiplier);

And your GapView will increase and decrease accordingly.

Mahesh Agrawal
  • 3,348
  • 20
  • 34
  • Nice approach, thank you... But, if I have a complex structure, then I should use more number of gapViews. Don't that increase the size of View Controller, I mean the size of app ? – John Wilkins Aug 10 '15 at 11:05
  • no, 1000 views with alpha 0 and clear color will not affect your screen performance or size of the app. am using in my every app and i didn't observed any kind of app size increase. – Mahesh Agrawal Aug 10 '15 at 13:54
  • Ooh, alright. Thank you...!! :) – John Wilkins Aug 11 '15 at 07:06