How to embed stack view in scroll

I tried to implement it, but my stack looks dynamic, and my application changes orientation from time to time. I have segment control at the end of the view. I also tried to take a walk, but no luck. thanks in advance.

So far I have done:

In the field of view was loaded:

mainStackView.axis = UILayoutConstraintAxis.Vertical mainStackView.spacing = 3 scrollView.frame = self.view.bounds scrollView.addSubview(mainStackView) view.addSubview(scrollView) 

Given the layout:

 override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() let top = topLayoutGuide.length let bottom = bottomLayoutGuide.length self.mainStackView.frame = CGRect(x: 0, y: top, width: view.frame.width, height: view.frame.height - top - bottom).insetBy(dx: 10, dy: 10) dispatch_async(dispatch_get_main_queue()) { self.scrollView.frame = self.view.bounds self.scrollView.contentSize = CGSize(width: self.view.bounds.width, height: self.segmentedControl.frame.origin.y + self.segmentedControl.frame.height + 50) } print(scrollView.contentSize) } 
+5
source share
1 answer

You need to set the height limit of the segment control.

Example:

  segmentedControl.heightAnchor.constraintEqualToConstant(50).active = true 

In addition, you can add an empty view from below to avoid introducing the stack that the mechanism should fill. This will show the desired viewing result.

  var bottomView = UIView(frame: CGRectZero) stackView.addArrangedSubview(bottomView) 
+2
source

Source: https://habr.com/ru/post/1241227/


All Articles