how set content size of textView's Scrollview

2019-08-16 18:12发布

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条回答
走好不送
2楼-- · 2019-08-16 18:43

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);
查看更多
登录 后发表回答