Search code examples
iosswiftuiscrollviewautolayout

Need Help in applying constraints to UIScrollView


I'm adding subviews programmatically. Requirement : when extra views are added the scroll should be enabled. The constraints that I applied : enter image description here

To remove extra spaces at the top I wrote self.automaticallyAdjustsScrollViewInsets = false also give content size as self.scrollView.contentSize = CGSize(width: self.contentView.frame.width, height: self.contentView.frame.height*2)

But the when the view is loaded scroll is completely disabled.

Please help me


Solution

  • When you using auto layout, you have to set content size at viewcontroller method, you have to override following method.

    -(void)viewWillLayoutSubviews;
    

    swift

    override func viewWillLayoutSubviews() {
    
        }