Not sure if there is a simpler way to do this, but if you have a button and you don’t want it to fill the entire StackView width and height, place it inside another view within the stackView and set leading/trailing/top/bottom constraints on it it.
How to preserve a button’s height and width in a UIStackView with distribution fill
July 10, 2017
Jan 03, 2019 @ 14:52:46
Thank you. This worked for me. I did it like this in Swift 4:
let wrapper = UIView(frame: CGRect.zero)
wrapper.addSubview(button)
button.centerXAnchor.constraint(equalTo: wrapper.centerXAnchor).isActive = true
stackView.addArrangedSubview(wrapper)
Jan 03, 2019 @ 16:29:50
Oops. I had to give the wrapper a size. Otherwise it seemed to keep the zero rect and wouldn’t pass the taps on to the button.
wrapper.heightAnchor.constraint(equalToConstant: 40).isActive = true
wrapper.widthAnchor.constraint(equalToConstant: 500).isActive = true
Jan 03, 2019 @ 21:11:12
Hey Murray – good to see ya!
Jan 04, 2019 @ 14:34:07
Hey, it’s you! email me if you get access to my email!