xcode – cocoa:如何使背景透明webView?

前端之家收集整理的这篇文章主要介绍了xcode – cocoa:如何使背景透明webView?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
mac osx,我想让我的webview看起来透明,并在其上显示数据,背景显示父视图的图像.

任何人都可以让我知道如何做到这一点?
这种方法不行

NSString * source = @"<html><head><title></title></head><body><div id=\"Box\">Example Box</div></body></html>";
[[webView mainFrame] loadHTMLString:source baseURL:[NSURL URLWithString:@""] ];
[[webView windowScriptObject] evaluateWebScript:@"document.getElementById('Box').style.backgroundColor = '#dddddd';"]; // Change Box background
[[webView windowScriptObject] evaluateWebScript:@"document.body.style.backgroundColor = '#dddddd';"]; // Change body background

解决方法

您需要在WebView上调用setDrawsBackground:并传入NO.这将阻止Web视图绘制背景,除非Web视图中加载的页面明确设置背景颜色.
原文链接:https://www.f2er.com/iOS/332768.html

猜你在找的iOS相关文章