androniennn
androniennn

Reputation: 3137

Change constraint value in function of screen size

I have 6 buttons UI like the following example: enter image description here

All is perfect with non retina and retina 3.5", however, with 4" retina I have such UI: enter image description here

What I think of solution is to change height constraint of every button in function of screen size programatically, I tried this code but it's not working:

self.todayHeightConstraint.constant =
    [UIScreen mainScreen].bounds.size.height > 568.0f ? 250: 250;

How to get rid of this white space and stretch buttons /change their constraint values in 4" screen?

Upvotes: 0

Views: 732

Answers (1)

Civatrix
Civatrix

Reputation: 2616

You need to constrain all the buttons to be the same height, then constrain A to the top of the superview, the top of C to the bottom of A, the top of E to the bottom of C, the bottom of E to the bottom of the superview. Then constrain the center of B, D & F to the button beside them. This should cause your buttons to stick to the edges of the screen and resize equally to fill the screen regardless of screen size.

Upvotes: 1

Related Questions