0

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

Timm
  • 169
  • 1
  • 13

1 Answers1

0

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.

Community
  • 1
  • 1
Timm
  • 169
  • 1
  • 13