Your constraints are likely not behaving like you expect. My strong suggestion is to use a UIStackView
instead, and bind it to the scroll view via constraints, but not your images.
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 8 // or whatever you want
stackView.addArrangedSubview(image1)
stackView.addArrangedSubview(image2)
scrollView.addSubview(stackView)
stackView.translatesAutoresizingMask = false
// finish the constraints like the first, but for .trailing, .top, and .bottom
NSLayoutConstraint.activate([
stackView.leadingAnchor(constraintEqualTo: scrollView.leadingAnchor),
...
])
1
solved How can you add padding between views in a UIScrollView in Swift? [closed]