How can we put constraints like
The vertical distance between two buttons must be '20 points' in the screen of height '568 points' and
must be '25 points in the screen of height '667 points' ?
How can we put constraints like
The vertical distance between two buttons must be '20 points' in the screen of height '568 points' and
must be '25 points in the screen of height '667 points' ?
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:
Hope this will help.
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.