-2

I've too much space below content in scroll view.

Please refer to the screenshot below. How do I fit scroll view to the content. The problem seems to be the bottom space. If I just leave it as per auto layout it gets too much space below the content.

If I set it to 8 it works but storyboard complains for constraints, see screenshot no. 2 below. If this can be fixed then I'll have solution.

I've seen some suggestions (e.g. How do I auto size a UIScrollView to fit the content) on other posts but they don't solve the issue. How to fix it?

enter image description here

enter image description here

Dan
  • 475
  • 9
  • 26

1 Answers1

1

Needed constraints:

  • ScrollView : top , leading , trailing , bottom

  • contentView : top , leading , trailing , bottom => to superView && equal width to main outer view

  • textView : top , leading , trailing , bottom => to contentView , height ( such as 50 )

BTW you don't need all of this as the UITextView inherits from UIScrollview, so it's scrollable by default.
If you need to resize it according to written text, then use:

self.textView.frame.size = self.textView.contentSize
Community
  • 1
  • 1
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
  • When you say "BTW you don't need all of this as the UITextView inh.." do you mean I don't need to set any constraints? – Dan Dec 30 '18 at 22:37
  • 1
    i mean you don't need the scrollview , just drag the UItextView directly – Shehata Gamal Dec 30 '18 at 22:39
  • I see yes you are right, didn't realise this simple thing. – Dan Dec 30 '18 at 22:41
  • 1
    Perfect solution as I applied it to my other VC where I had many views inside content view and it worked. I followed some other tut and I was doing it all wrong. I was giving contentView equal height as well and textView bottom was pinned to scroll view rather than contentView. Tx again you saved a lot of my time. – Dan Dec 30 '18 at 23:56