Autolayout ScrollView with dynamic content

im going crazy on autolayout and dynamic scrollview heigth.

I want to make my scrollview content height based on the content in multiple textviews. Also the spacing between the textviews should stay the same.

Therefor i tried to make a small sample app with two textviews and a button which calls [textview sizeToFit] for each textview. Another thread suggested to set the bottom verticl spacing of the lowest view to the scrollview (see screen1)

Following problems:

  • The vertical spacing between the textviews does not apply correctly (see screenshot3)
  • After applying [textview sizeToFit] the scrollview isnt scrollable and its size stays the same. Also only textview1 gets scrollable (is set NO in IB)

Im glad for any help or step-by-step tutorials. Another thought I had: Would it make sense to put those textviews in a tableview and make cells heigth depending on content, so I dont habe to struggle with scrollview stuff?

More details are on the screenshots: constraints before sizeToFit after sizeToFit


ANSWERS:


I got it figured out, using a UITableView with a custom cell, containing a label on left side and a textview on the right side.

To get the dynamic height in UITableView I used the answer provided in this thread: Dynamic Height iOS7.

Further more I added 2 constraints to the UITextView (top and bottom to the cell's content view) to stretch the UITextView to same height as the cell.

Though its not the answer that i wanted (since i tried to use autolayout-only), I hope others can use this approach.



 MORE:


 ? Using a textView and ScrollView in the same ViewController does not work? Swift
 ? How to adjust the height of a textview to his content in SWIFT?
 ? How to dynamically adjust height of UITextView
 ? Get number of lines in UITextView without contentSize.height
 ? Get number of lines in UITextView without contentSize.height
 ? Get number of lines in UITextView without contentSize.height
 ? Background Image for UITextView
 ? iOS7 UITextView contentsize.height alternative
 ? Get number of lines UITextView without using "\n"?
 ? UITextView does not update its height after trying to change its height programmatically