0

I am trying to add a border to a group of buttons that are all within the same stack view. I want the buttons to share the same leading and trailing borders, and the edges of the group of buttons to be rounded.

I tried embedding the buttons in a stack view, then embedding the buttons in views within the stack view, but still have not been able to get it right.

LobstaBoy
  • 515
  • 1
  • 3
  • 10

1 Answers1

0

First apply layoutMargins with UIEdgeInsets to have spacing, then for each button in stackView, change cornerRadius

    stackView.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20) // change 20 with your value.
    // then for each of subviews in stackview, if it is a button, apply corner radius
    stackView.subviews.forEach { view in
        if view is UIButton {
            view.layer.cornerRadius = 5 // replace it with your value.
        }
    }
emrepun
  • 2,496
  • 2
  • 15
  • 33
  • Sorry, this was kinda a noob question and I was able to make what I wanted by just embedding the buttons in a stack view and adjusting the Spacing to -1 in the Attributes inspector, then added the code from: https://stackoverflow.com/questions/26961274/how-can-i-make-a-button-have-a-rounded-border-in-swift to get the borders. Thank you for the answer. – LobstaBoy Dec 23 '18 at 17:44