Since you want to have 4 buttons, horizontally aligned, I would suggest you use a UIStackView
with vertical axis
. You can set its contentMode
to be Fill Equally
and add your 4 buttons as children to the UIStackView
. Regarding your question "how to constraint a view programatically", this is how you can achieve this (this is just an example of a view constraint to the bottom of the screen with height equal to 80):
var yourView = UIView()
// Pin the leading edge of yourView to the leading edge of the main view
yourView.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true
// Pin the trailing edge of yourView to the leading trailing edge
yourView.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor).active = true
// Pin the bottomedge of yourView to the margin's leading edge
yourView .bottomAnchor.constraintEqualToAnchor(view.bottomAnchor).active = true
// The height of your view
yourView.heightAnchor.constraintEqualToConstant(80).active = true