dimanche 26 juin 2016

UIScrollView that expands with contents' instrinsic size until height X, and then scrolls

I'm basically trying to reproduce the behavior of the title and message section of an alert.

enter image description here

The title and message labels appear to be in a scroll view. If the label text increases then the alert height also increases along with the intrinsic content size of the labels. But at a certain height, the alert height stops increasing and the title and message text become scrollable.

What I have read:

Articles

Stack Overflow

The answer may be in there but I was not able to abstract it.

What I have tried:

Only focusing on the scroll view with the two labels I tried to make a minimal example in which a parent view would resize according to the intrinsic height of the scrollview. I've played around with a lot of constraints. Here is one combo (among many) that doesn't work:

enter image description here

I've worked with auto layout and normal constraints and even intrinsic content sizes. Also, I do know how to get a basic scroll view working with auto layout. However, I've never done anything with priorities and content hugging and compression resistance. From the reading I've done, I have a superficial understanding of their meanings, but I am at a loss of how to apply them in this instance. My guess is I need to do something with content hugging and priorities.

Update

I have accepted an answer, but if anyone can show how to do this with pure autolayout, I will award the bounty to them.

Aucun commentaire:

Enregistrer un commentaire