How can I scale the content of a WebView?
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];
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];
}
Javascript is your bestfriend:
[_webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.zoom = \"0.5\""];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With