Also distribute buttons in Xcode

advertisements

I have 4 buttons which are supposed to be at the bottom of my screen, right next to each other -- 0 pixels apart. I want it to work for any screen size, or at least for iPhone 5, 6, and 6+. I'm trying to add constraints, but it doesn't do what I want it to do.

It's my first time working with Swift and XCode, please give me a hint.

Thanks in advance!


The best practice is to use UIStackView

  • Just drop it to storyboard
  • Add vertical spacing constraint to bottom layout guide
  • Add horizontal spacing constraints to leading and trailing of the superview
  • Add height constraint
  • Now add the buttons as subviews of the stack view
  • set the stack views properties: Horizontal, distribution and alignment as you want

Good luck