简体   繁体   中英

How would I create a UIView with two UIWebViews and another UIView and dynamically change the parent UIView size to contain the content views?

I want to have one big view (probably with scroll). It'll show in vertical:

  • One HTML string --> 1 webview
  • Other HTML string --> 1 webview
  • One view with buttons and labels. (fixed size)

I'd want to calculate the heights of the webviews (in webViewDidFinishLoad) for setting the final size of the parent UIView, but in some cases the height of the parent view will be huge so I guess I'll need a scrollview in this case.

What's the best way for doing this?

Your view structure should look like this. View Controller -> View -> Scroll View -> View -> All your other stuff.

In your webViewDidFinishLoad method you will want to calculate the height of the content in the UIWebview. Once you have calculated that height set your UIWebview you use that height and reload them. Once the Webview height had been calculated via the content but not applied, you can calculate the total height of all your other stuff.

Take the height of all your other stuff and apply it to your View just inside the scroll view. For scrolling to work you will need to make sure that your scroll view height is actually smaller than the height of it's contents (the view containing all your other stuff).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM