Search code examples
iosxamarin.iosuiwebview

UIWebView auto changing its height inside scrollview


I'm trying to include disqus in my app (commentaries API) in Xamarin studio.

What I have now is scrollview in which programmatically added some text and pictures from URL.

I want to add UIWebView at the bottom of the scrollview, but the height of webview can be different, so it cannot be set.

Is it possible for webview to change its size because of content size (i don't want to have scrollview inside scrollview, so scrolling a webview is not an option).

I'm not asking about the solution, just some ideas if it's possible. Thanks


Solution

  • If it's possible for you to use WKWebView instead of UIWebView, you can implement the same behavior (in terms of loading the URL and it's contents, etc.). WEKWebView exposes the scrollView property.

    You can observe the "contentSize" property on that UIScrollView, and adjust your main scroll view's contentSize accordingly. Managing the contentOffset when this happens is a different thing all together.

    Since your parent scrollView will always fully contain the webview, it won't scroll, leaving your user to be able to only scroll through the main view.