0

I need a view that contains (title, image, and details), the details is about a textview.

what I need is, to allow scroll to all the view, not just for the texview. in my application, if I disabled scroll, the textview is cut, because the height is not dynamic:

enter image description here

in my code, I put like this:

  CGRect frame = self.detailTextView.frame;
  frame.size.height = self.detailTextView.contentSize.height;
  self.detailTextView.frame = frame;
  [self.detailTextView sizeToFit];
  self.detailTextView.text = [[fastResults objectAtIndex:0] objectForKey:@"content"];

which fastResults is a dictionary that contains data.

I need the view like for example bbc application:

enter image description here

SO, I need to let the textview height is dynamic and to let all the view is scrollable together. Note: All these elements are in a scrollview.

this is my interface builder:

enter image description here

Thank you for your help;

CarinaM
  • 527
  • 4
  • 12
  • 27

2 Answers2

0

First of all you have to set the text on the text view before you resize it. So you should have something like:

  self.detailTextView.text = [[fastResults objectAtIndex:0] objectForKey:@"content"];
  CGRect frame = self.detailTextView.frame;
  frame.size.height = self.detailTextView.contentSize.height;
  self.detailTextView.frame = frame;
//  [self.detailTextView sizeToFit]; you don't need this anymore

//after you resized the self.details.textView you have to change the scrollview content size 

yourScrollView.contentSize = CGSizeMake(yourScrollView.contentSize.width, 
                                       yourImageHeight + yourTitleHeight + self.detailsTextView.frame.size.height);
danypata
  • 9,895
  • 1
  • 31
  • 44
  • still the text cut off, should I edit something in the storyboard inspectors? – CarinaM May 11 '13 at 10:04
  • are you using autoLayout ? – danypata May 11 '13 at 10:08
  • I've attached a screenshot of my interface builder, in the view inspector element the frame rectangle is selected, what do you mean by autolayout??? – CarinaM May 11 '13 at 10:13
  • Yep you are using autolayout (the new feature added in iOS 6 to support different screen sizes). So please check that your constraints on your views allow the text view to increase his height. – danypata May 11 '13 at 10:16
  • please check the attached screenshot, I've updated to display the constraints, what shall I do with the constraints???? – CarinaM May 11 '13 at 10:20
  • You should check http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2 fot autolayout details. It's very hard to change constraints based on a screenshot. – danypata May 11 '13 at 10:23
  • If you got the answer for your question you should mark it as accepted so that the question won't appear to the unanswered section. ;) – danypata May 12 '13 at 18:55
0

You can get first the height of the NSString you are putting in the textview (see this), then set the height of the textview as the calculated height of the string.
Maybe, if the height of the textview is greater than the height of the scrollview contentSize, you have also to adapt the height of the contentSize of the scrollview as the height of the textview's frame. And then disable the scrolling on the textview.

Community
  • 1
  • 1
Mat
  • 7,613
  • 4
  • 40
  • 56