0

I've been trying to achieve something like the example below for quite a while now without success.

Here's what I have so far:

H:|[firstView][secondView(== firstView)][thirdView(== firstView)][fourthView(== firstView)]|

Which works, but, it yields this result:

current

I'm trying to get it to look like this:

target

In other words, I'm trying to place 4 UIViews with equal width and fixed height, on the bottom of the screen.

Does anyone have any input or reference to visual format constraints?

COOKIES
  • 434
  • 4
  • 14

1 Answers1

2

I'm not too sure how to do multiple views in a single constrait but here is how you would do it one view at a time.

This would do your left and right constraints:

NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[V]-0-|", options: [], metrics: nil, views: ["V" : firstview]))

This would constraint the view to the bottom of the screen:

NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "V:[V]-0-|", options: [], metrics: nil, views: ["V" : firstview]))

Then to add a height constraint:

NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "V:|[V(25)]|", options: [], metrics: nil, views: ["V" : firstview]))
Harry Singh
  • 826
  • 5
  • 11