how set content size of textView's Scrollview immediately when user starts scrolling or when tap on textview

假装没事ソ 提交于 2019-12-12 03:39:13

问题


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);


来源:https://stackoverflow.com/questions/13721721/how-set-content-size-of-textviews-scrollview-immediately-when-user-starts-scrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!