UIWebView set initial zoom scale programmatically when loading an external website?

后端 未结 5 1002
日久生厌
日久生厌 2020-12-17 02:28

What I want to do is set the initial zoom scale [and in some cases, content offset, but that is less important] for an external website. But after the app initially sets th

相关标签:
5条回答
  • 2020-12-17 03:00

    Why not:

       [self.webView.scrollView setZoomScale:2.0 animated:YES];
    
    0 讨论(0)
  • 2020-12-17 03:07

    if you are loading html and javascriptin uiwebview then in viewport set user-scalable=1.0.

    0 讨论(0)
  • 2020-12-17 03:08

    Try this for setting the initial zoom level -

    [webView stringByEvaluatingJavaScriptFromString:@"document. body.style.zoom = 5.0;"];
    

    Also dont forget to set scalesPageToFit to NO and you're done.

    If you set this to YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.

    0 讨论(0)
  • 2020-12-17 03:08

    best one found try adding meta tag in your html page,in your tag.It gets repaired in a eye blink. Try the apple link and select the suitable meta tag for you.

    0 讨论(0)
  • 2020-12-17 03:12

    If you want to set initial zoom for your web view and then your web view can scaleable. You can try to add meta tag into the head tag of your HTML string at webViewDidFinishLoad protocol method. You can change 'initial-scale', 'minimum-scale'and 'maximum-scale' to adapt to your required. Looks like this:

    - (void)webViewDidFinishLoad:(UIWebView *)webView {
        NSString* js =
        @"var meta = document.createElement('meta'); " \
        "meta.setAttribute( 'name', 'viewport' ); " \
        "meta.setAttribute( 'content', 'width = device-width, initial-scale = 1.0,minimum-scale=1.0,maximum-scale=10.0 user-scalable = yes' ); " \
        "document.getElementsByTagName('head')[0].appendChild(meta)";
        [webView stringByEvaluatingJavaScriptFromString: js];
    }
    
    0 讨论(0)
提交回复
热议问题