Scale WebView in Cocoa

后端 未结 4 983
名媛妹妹
名媛妹妹 2020-12-06 18:15

How can I scale the content of a WebView?

相关标签:
4条回答
  • 2020-12-06 18:31

    A WebView is an NSView, so one way would be to send it a scaleUnitSquareToSize: message.

    0 讨论(0)
  • 2020-12-06 18:36

    You need to call -scaleUnitSquareToSize: on the document view of the individual frame that you want to resize, for example the main frame:

    [[[[webView mainFrame] frameView] documentView] scaleUnitSquareToSize:NSMakeSize(1.5, 1.5)];
    [[[[webView mainFrame] frameView] documentView] setNeedsDisplay:YES];
    
    0 讨论(0)
  • 2020-12-06 18:37

    Or you can try the following:

    - (IBAction)takeZoom:(NSSlider *)sender {
        WebView *aWebView = [[window.contentView subviews] lastObject];
        NSView *clipView = [[[[aWebView mainFrame] frameView] documentView] superview];
        float scale = pow( 4, [sender floatValue] )/(clipView.frame.size.width/clipView.bounds.size.width);
        [clipView scaleUnitSquareToSize:NSMakeSize(scale, scale)];
        [clipView setNeedsDisplay:YES];
    }
    
    0 讨论(0)
  • 2020-12-06 18:42

    Javascript is your bestfriend:

     [_webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.zoom = \"0.5\""];
    
    0 讨论(0)
提交回复
热议问题