I am making a UIScrollView with a UIStackView inside it programmatically.
The UIScrollView does not scroll even though the UIStacVview that is inside it has a much larger width.
Here is my code:
view.backgroundColor = UIColor(red: 0.161, green: 0.165, blue: 0.188, alpha: 1.00) // 292a30
view1.backgroundColor = UIColor.green
view2.backgroundColor = UIColor.yellow
view3.backgroundColor = UIColor.gray
view4.backgroundColor = UIColor.white
view5.backgroundColor = UIColor.orange
scrollView.backgroundColor = UIColor.red
scrollView.frame = CGRect(x: 10, y: 100, width: view.frame.width - 20, height: 100)
scrollView.translatesAutoresizingMaskIntoConstraints = false
stackView.backgroundColor = UIColor.blue
stackView.axis = .horizontal
stackView.spacing = 10
stackView.distribution = .fillEqually
stackView.frame = CGRect(x: 0, y: 0, width: view.frame.width + 200, height: 100)
stackView.addArrangedSubview(view1)
stackView.addArrangedSubview(view2)
stackView.addArrangedSubview(view3)
stackView.addArrangedSubview(view4)
stackView.addArrangedSubview(view5)
scrollView.addSubview(stackView)
view.addSubview(scrollView)
What is working:
- The
UIStackViewloads and looks like this:
- The
UIStackViewstretches out the side of theUIScrollView.
What is not working:
- You cannot scroll with the
UIScrollView, it is just like it isn't there.
