I've struggling a lot with UIScrollView to add programmatically subviews, I've seen a lot of tutorials but they all focus on storyboards and don't really solve my issue I'm just trying to add a few subviews to a scrollView but don't get to show anything on the device, it only displays the scrollView without my subviews, im trying to do something like this:
view.addSubview(mainScrollView)
mainScrollView.anchor(top: view.safeAreaLayoutGuide.topAnchor, right: view.rightAnchor, bottom: view.bottomAnchor, left: view.leftAnchor, topPadding: 10, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: 0, height: 0)
let v1 = UIView()
v1.backgroundColor = .blue
let v2 = UIView()
v2.backgroundColor = .black
let v3 = UIView()
v3.backgroundColor = .yellow
let v4 = UIView()
v4.backgroundColor = .green
mainScrollView.addSubview(v1)
mainScrollView.addSubview(v2)
mainScrollView.addSubview(v3)
mainScrollView.addSubview(v4)
v1.anchor(top: mainScrollView.topAnchor, right: nil, bottom: nil, left: nil, topPadding: 0, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: mainScrollView.contentSize.width, height: 0)
v2.anchor(top: v1.bottomAnchor, right: nil, bottom: nil, left: nil, topPadding: 0, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: mainScrollView.contentSize.width, height: 0)
v3.anchor(top: v2.bottomAnchor, right: nil, bottom: nil, left: nil, topPadding: 0, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: mainScrollView.contentSize.width, height: 0)
v4.anchor(top: v3.bottomAnchor, right: nil, bottom: mainScrollView.bottomAnchor, left: nil, topPadding: 0, rightPadding: 0, bottomPadding: 0, leftPadding: 0, width: mainScrollView.contentSize.width, height: 0)
anchor is just a helper extension to make it easier to constrain and activate the constraints