pprevalon pprevalon - 1 month ago 7
Swift Question

Swift how to increase margins of arranged views

How can Increase the the margin of different

UITextFields
inside a
UIStackView
. I need to increase the the top margin the margins will be the same.

let formWrapperStackView:UIStackView = {
let v = UIStackView()
v.axis = .vertical
// v.distribution = .fillProportionally
v.spacing = 0
v.translatesAutoresizingMaskIntoConstraints = false

return v
}()


enter image description here

Answer

It is not possible to have different spacing for different elements in a UIStackView. So a solution would be to wrap each of your textfields with a UIView and then set the top constraint of each textfield (between textfield and UIView) to your desired margin.