Programmatically resize / adjust dynamic html to fit UIWebView

The requirement is to fit an HTML to a UIWebView with fixed size(s) ie predefined width x height combinations, these sizes could be specified by the developer. About the HTML, it contains scripts that further load other html(s) having dynamic elements, the nature of which is not known at runtime as the dynamic html(s) basically are rich media ads (advertisements). What I have tried from among the several 100 solutions posted for similar questions on SO:

  • Changing the meta viewport width & height to that of the webview (https://developers.google.com/webmasters/mobile-sites/mobile-seo/responsive-design && http://webdesignerwall.com/tutorials/viewport-meta-tag-for-non-responsive-design)
  • CSS update of canvas & div elements width/max-width & height/max-height to that of the webview (based on testing which showed these elements being the main ones that form the HTML) through script tags (http://codetheory.in/scaling-your-html5-canvas-to-fit-different-viewports-or-resolutions/ , HTML Content fit in UIWebview without zooming out)
  • Javascript injection to update canvas & div elements.
  • The issue: regardless of the above 3 changes applied together or as a combination fails to render the HTML properly inside the webview. Either the elements overflow or they shrink and as a result the display is never 'correct'. This leads me to believe that this is altogether not possible because

  • The layout of the HTML elements cannot be controlled based on their sizes alone since they work together and altering them incorrectly is not advised
  • The initial HTML could load any other HTML with elements other than divs and canvas' etc.
  • Applying the aforementioned approaches will result in the html being distorted as all divs and canvas' would be treated the same way, regardless of their width & height
  • I've not posted the actual code of the approaches tried above as none have worked & I think that they won't cater to dynamic HTML(s). I am at a dead end and would appreciate if someone could confirm my beliefs and validate them or point me towards a solution. If such a solution is said to not be possible at an app level (in the UIWebView), then maybe I could convince the html providers to deliver size based HTMLs instead. Any help is appreciated.


    - (void)webViewDidFinishLoad:(UIWebView *)webView {
            CGRect newBounds = webView.bounds;
            newBounds.size.height = webView.scrollView.contentSize.height;
            webView.bounds = newBounds;
    }
    

    (新泽西州)

    链接地址: http://www.djcxy.com/p/77426.html

    上一篇: 在UIScrollView中添加UIWebView XAMARIN.IOS C#

    下一篇: 以编程方式调整/调整动态html以适应UIWebView