UIScrollview with auto layout

I am afraid of UIScrollView now.

"descriptionLabel" and "genresLabel" will increase the height at runtime, and the gap between participants will widen. So I need a scroll function to see the shortcuts to the actors.

I set the height of the contentView to a height constraint equal to the view with a priority of 250 and hoped the height would increase automatically if needed.

Nothing really happens and scrolling is not possible.

How can I automatically increase the height of the contentView in the auto layout context?

Storyboard

+3


source to share


5 answers


You have to make the ContentView height flexible so that it grows and the scroll content grows accordingly. Check out the attached screenshots. Increase the limit of the bottom label (which is 495), the size of the scroll content will be automatically increased.

Here is a Sample Source Code

enter image description here



enter image description here

enter image description here

+3


source


Is your label Actors the final piece of this show? If after that we fix both Actors: and asdfas ... top, bottom and left. Now for the lower value, set "Constant" to "Use default value". Also fix the top-most item (here maybe "No network connection!"), And set its "Constant" to "Use default". Try this and let me know if it works!

I tried what I told you. Having images of the same. Hope it helps! enter image description here

enter image description here



enter image description here For Actors shortcut restrictions:

enter image description here and for constraints the asdfas labels are given in the following image: enter image description here

+1


source


Just check this link, just write this to add content view height: -

override func viewDidLayoutSubviews()
    {
        let scrollViewBounds = scrollView.bounds
        let containerViewBounds = contentView.bounds

        var scrollViewInsets = UIEdgeInsetsZero
        scrollViewInsets.top = scrollViewBounds.size.height/2.0;
        scrollViewInsets.top -= contentView.bounds.size.height/2.0;

        scrollViewInsets.bottom = scrollViewBounds.size.height/2.0
        scrollViewInsets.bottom -= contentView.bounds.size.height/2.0;
        scrollViewInsets.bottom += 1

        scrollView.contentInset = scrollViewInsets
    }

      

0


source


It's hard to figure out what's wrong with your layout, so I created a test project with 2 growing shortcuts, everything works fine, maybe you can find out what is wrong in your constraints :)

https://www.dropbox.com/s/j8269c03b32gra5/scrollview-test.zip?dl=0

Build my project and click the More Text button to dynamically add text to the labels in the scrollview

0


source


For me, I needed to add a bottom constraint for my last element on the page. More explained here

0


source







All Articles