how set content size of textView's Scrollview

2019-08-16 17:56发布

问题:

I have UITextView in that in include image/ (UIImageView ).

But when i want to see the image it is unable to see / scroll,

i implemented logic to increase the scroll content size dynamically with respective to the text size,

- (void)scrollViewDidScroll:(UIScrollView *)scrollview 
{
      if (scrollview.contentOffset.y >= scrollview.contentSize.height - scrollview.frame.size.height) 
      {

            CGSize s = [messageView.text sizeWithFont:[UIFont systemFontOfSize:25] //define your textview font size
                                    constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT)  // - 40 For cell padding
                                        lineBreakMode:UILineBreakModeWordWrap];   

            // To increase the text view scroll content to display image also
            [scrollview setContentSize:CGSizeMake(200, s.height+150)];

      }       
}

but it starts scrolling only when text in the text view exceeds its (textview) bounds.

I was unable to see the full image if the text is with in bounds (no of lines can fit in text view)

How to set scroll size when touch / starts scrolling on textview,,

回答1:

use this code after set the text to the messageView(UITextView)

    messageView.frame = CGRectMake(messageView.frame.origin.x, messageView.frame.origin.y, messageView.frame.size.width, messageView.contentSize.height + 150);
    float fscrview = messageView.frame.origin.y + messageView.frame.size.height + 150;
    scrollview.contentSize=CGSizeMake(320, fscrview);