-2

I need to dynamically create a UIView at the bottom of the screen , which need to contain 4 buttons horizontally (eg. button1 , button2 , button3 , button4). And the problem is I couldnt able to set the constraints for it , could any one suggest me .

Thanks inadvance.

Riya
  • 15
  • 3
  • what have you tried so far? Please add some code. there is a pretty good explanation of setting constraints here http://stackoverflow.com/questions/31651022/how-to-create-layout-constraints-programmatically – HarmVanRisk Feb 17 '17 at 14:45

1 Answers1

1

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
Stefan Stefanov
  • 829
  • 7
  • 23
  • Thanks for your response . could you please specify this in objective- c , sorry i am new to ios . – Riya Feb 17 '17 at 15:42