Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale WebView in Cocoa

How can I scale the content of a WebView?

like image 312
Matt S. Avatar asked Feb 02 '10 02:02

Matt S.


3 Answers

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];
like image 64
Rob Keniger Avatar answered Nov 13 '22 02:11

Rob Keniger


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];
}
like image 28
Wanderer Avatar answered Nov 13 '22 01:11

Wanderer


Javascript is your bestfriend:

 [_webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.zoom = \"0.5\""];
like image 2
Altimac Avatar answered Nov 13 '22 01:11

Altimac