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

4
  • 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. Commented Mar 18, 2016 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? Commented Mar 18, 2016 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. Commented Mar 18, 2016 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 Commented Mar 18, 2016 at 12:01

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

3 Comments

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)
Then you probably want to look at this: stackoverflow.com/questions/728704/resizing-uitextview
Thank, that is exactly what I was looking, although unsure how properly ask the question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.