5

I have tried embedding it, but my stack view is dynamic and my app is also changing orientations time to time. I have segment control at the end of the view. I have also tried googling it but had no luck. thanks in advance.

So far I have done:

In view did load:

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

In view did 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)
    }

1 Answer 1

2

You need to set the height constraint of segment control.

For Example:

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

More over, you can Add Empty bottom view to avoid stack view's must fill mechanism. This will show you desired view output.

        var bottomView = UIView(frame: CGRectZero)
        stackView.addArrangedSubview(bottomView)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.