3
votes

I am having trouble getting the buttons to always stay at 50pts, no matter the screen size. I can get them the have the correct leading and trailing contraints but they shrink in height based on the screen size. for example:

iPhone SE screen

iPhone 6s plus screen

iPhone 6 screen

My constraints are set up so that all buttons have equal widths and heights at 599 x 50 and 20pts from each edge, not constraining to margins. Any help/direction would be great. Thanks!

2
Have you tried increasing the priority of the height constraints to max? - Jeff Wolski
I'm new to xcode; That would be setting them all to 1000? Yeah, they are. - GrantW
you haven't set a HEIGHT constraint, if you added a fixed height constraint to any of your buttons, they would stay constant - MSU_Bulldog
I set the top button height constraint = 50 and then dragged the rest of them to have equal heights and widths as the top. Is there another/better way to do it? - GrantW

2 Answers

2
votes

Go to each button and set its height constraint to 50pts. That should solve your issue. If not, you could try it in code:

override viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    NSLayoutConstraints.activate([
        <BUTTON>.heightAnchor.constrain(equalToConstant: 50)
    ])
}
2
votes

Go to button and write the code otherwise you have one more option by setting it through autolayout on story board or xib file.

You can check with the video also might be it can help you out.

https://youtu.be/SyDDw1V9cU4