6

I have a scrollView, which has two subViews: an imageView and a textView. When there is a small text in the textView everything is fine,but , when the content of textView is too big for the height of textView, it doesn't expands the boundaries. Instead of this, it offers me to scroll the textView. But i want to scroll only the scrollView.So how can i make textView resize automatically?

I know how to do it without auto layout, but i want to know how to do it with auto layout;

igrrik
  • 467
  • 1
  • 6
  • 16
  • see also http://stackoverflow.com/questions/27652334/uitextview-inside-uiscrollview-with-autolayout/30633898#30633898 – Suragch Jun 04 '15 at 02:37

1 Answers1

5

Update: My answer was bad. Better approach is presented in Scroll Views Inside Scroll Views.

Arek Holko
  • 8,966
  • 4
  • 28
  • 46
  • I'm sorry, but it doesn't work. Also there is a "conflicting return type", when i'm trying to override intrinsicContenSize. – igrrik Oct 21 '13 at 20:09
  • @igrrik: `intrinsicContentSize` is a separate method. You shouldn't put the code into `drawRect:`. – Arek Holko Oct 21 '13 at 20:20
  • @igrrik: can you explain in more details than "doesn't work"? – Arek Holko Oct 21 '13 at 20:29
  • I am doing the master-detail app. Master view has tableView with news. When i choose a cell, detail-view appears. There is an image and a text of the chosen article. Both imageView and textView have standard constraints, and also i added textViewHeightConstraint.ImageView's width is 320,height is 350. After imageView there is a textView. The problem is that when the text of the article is too big, if i want to read it i have to scroll the textView, not the scrollView. – igrrik Oct 21 '13 at 20:45
  • @igrrik: My answer was wrong, I've fixed the code in `intrinsicContentSize`. – Arek Holko Oct 21 '13 at 21:40
  • I've created a subclass of textView and overrided the intrinsicContentSize as you said. Then I made the textView to be the inheritor of the subclass of textView. I called [self.textView invalidateIntrinsicContentSize], but nothing changed. – igrrik Oct 22 '13 at 11:05
  • @igrrik: I've tested it more thoroughly today. There're some small problems with using `intrinsicContentSize`, so I advise to use the constraint instead. This is the approach I use in my apps. – Arek Holko Oct 22 '13 at 11:23
  • I'm already using constraints. All of my views have constraints. In textView there are 5 of them: 1)leading alignment textView-imageView. 2)vertical space textView-imageView (space between them) 3)vertical space scrollView-textView 4)horizontal space scrollView-textView 5)height of the textView (which automatically set to 210, and i cannot make it bigger). – igrrik Oct 22 '13 at 11:34
  • @igrrik: OK, you have to change the `constant` of the 5th constraint (`height of the textView`) as I described in my answer. – Arek Holko Oct 22 '13 at 11:35
  • I've already did it yesterday. I've tried now, and it doesn't work. Here is the link to my project, I will be very grateful, if you look at it, because I don't know whom to ask, and I can't fix it for fourth day. There are 11 articles int he tableview. First 5 have few text, others have more, at the end of the text of every article, I've added word "END", so you can understand whether the text is shown fully. https://www.dropbox.com/s/tx1q3gjdapx39f8/NewsCatalogue.zip – igrrik Oct 22 '13 at 12:02
  • https://dl.dropboxusercontent.com/u/5184129/code/NewsCatalogue_fixed.zip Things I changed 1) Removed `intrinsicContentSize` from NCTextView (as it's no longer needed) 2) connected the outlet to `textViewHeightConstraint` 3) removed the constraint between the `Image View` and the bottom of the `scroll view` – Arek Holko Oct 22 '13 at 12:14
  • @igrrik: let me know if it is what you wanted to achieve. – Arek Holko Oct 22 '13 at 12:24
  • Yes it works! You are my hero. Also after you removed the constraint between the Image View and the bottom of the scroll view, there was an error and you added a constraint "vertical space-Scroll View - Text View". Thank you very much!!! Could you please tell me what was my mistake or what do these two lines of code in your answer do? – igrrik Oct 22 '13 at 12:35
  • @igrrik: The constraint 3) (`between the Image View and the bottom of the scroll view`) was keeping the scroll view from extending. It was the main mistake. My code calculates what height the text view should have to not need any scrolling. Then this height is set as a `height constraint` of the text view. – Arek Holko Oct 22 '13 at 12:40