可可:如何使背景透明的webView? [英] cocoa: How to make background transparent webView?

查看:84
本文介绍了可可:如何使背景透明的webView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mac osx,我想使Webview看起来透明,并在其上显示数据,并在背景上显示父视图的图像.

The mac osx ,I want to make my webview to look transparent and show the data on it with background showing images of parent view.

任何人都可以让我知道如何执行此操作吗? 这种方法不能

Can anyone please let me know how to do this? This method can not

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视图绘制背景.

You need to call setDrawsBackground: on the WebView and pass in NO. That will prevent the web view from drawing a background unless the page loaded in the web view explicitly sets the background color.

这篇关于可可:如何使背景透明的webView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆