UIWebView的内容背景颜色不透明

Phi*_*lip 2 css objective-c uiwebview ios

我正在使用UIWebView从plist加载一些HTML文本.

我设法使其背景透明化

webView.opaque = NO;
webview.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)

但是内容,即从plist加载的文本,以令人不安的白色背景显示.

我正在加载它

NSString *descr = [NSString stringWithFormat:@"<html><head><style> body{font-size:16; font-family: Helvetica; color: black;} strong{font-family: Arial; font-weight: bold; font-size:16} .bg{background:transparent;}</style></head><body><div class='bg'>%@</div></body></html>",[item valueForKey:@"description"]];
[webView loadHTMLString:descr baseURL:nil];
Run Code Online (Sandbox Code Playgroud)

我已经尝试将.bg类背景颜色设置为rgba(255,0,0,0.0),但没有任何效果.

也试过设置 webView.scrollView.backgroundColor : [UIColor clearColor];

关于如何让UIWebView的内容背景透明的任何建议?

Bej*_*bun 10

试试这个 !

[webView setOpaque:NO];
webView.bakgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)