如何扩展WebView的内容?
答案 0 :(得分:11)
您需要在要调整大小的单个帧的文档视图上调用-scaleUnitSquareToSize:
,例如主框架:
[[[[webView mainFrame] frameView] documentView] scaleUnitSquareToSize:NSMakeSize(1.5, 1.5)];
[[[[webView mainFrame] frameView] documentView] setNeedsDisplay:YES];
答案 1 :(得分:5)
或者您可以尝试以下方法:
- (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];
}
答案 2 :(得分:2)
Javascript是你最好的朋友:
[_webview stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.zoom = \"0.5\""];
答案 3 :(得分:-2)
WebView是NSView,因此一种方式是to send it a scaleUnitSquareToSize:
message。