2

I have a scrollView which contains textView. If text is long and does not fit on a screen, I would like to increase textView height (which I think I could do by adding NSLayoutConstraint outlet and modifying it, correct me if I am wrong) so that view would be scrollable (or non scrollable) depending on text length. Pretty much, like I can set Scrolling Enabled for textView, except I wan to scroll whole view because of images and labels I have on that view.

EDIT. Basically - how to guess textView height based on string, in order to have proper size textView

Xernox
  • 1,706
  • 1
  • 23
  • 37
  • NSTextview scrolls by itself already, why do you need this ? Just use textview without the scrollView. It will scroll outside whenever the text is too long. – erenkabakci Mar 18 '16 at 11:48
  • Yes and it will be ugly. I want whole view scroll if text is too long. Pretty much like any website on iPhone works - if text is too long, whole view will scroll, otherwise will not. Or am I missing something? – Xernox Mar 18 '16 at 11:51
  • actually your solution is worse than this one. You need to handle both element's scrolling behaviors. Also putting scrollviews inside scrollviews is already something nasty even as Apple says. Make your textView as big as your screen and whenever the text is too long it will just scroll and look natural. – erenkabakci Mar 18 '16 at 11:54
  • I made my textView unscrollable - so the only moving part is scrollView. If I understand correctly, you are suggesting to make images, labels static and the text scrollable? To better understand what I want, open any website - BBC.com find any article and the article will scroll together with all images, not just text and that is what I want and it's possible I saw an app that does exactly that – Xernox Mar 18 '16 at 12:01

1 Answers1

1

To make your scrollview content scrollable you need to set the size of your UIScrollView content ( your textview ), e.g. use:

scrollView.contentSize = CGSizeMake(textview.frame.size.width, textview.frame.size.height)
dijipiji
  • 3,063
  • 1
  • 26
  • 21
  • Yes, I understand that, but the main thing is how to set proper textView height based on a string (text that will be in that textView) – Xernox Mar 18 '16 at 12:02
  • 1
    Then you probably want to look at this: http://stackoverflow.com/questions/728704/resizing-uitextview – dijipiji Mar 18 '16 at 12:07
  • Thank, that is exactly what I was looking, although unsure how properly ask the question. – Xernox Mar 18 '16 at 12:11