0

此代码在 ios 6 中有效,但在 ios 5 中无效。知道吗?

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bg10.jpg"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:path isDirectory:NO];

NSString *htmlString = [[NSString alloc] initWithFormat: @"<html><body background=\"%@\"></body></html>",url];

[self.WebView setOpaque:NO];
self.WebView.backgroundColor = [UIColor clearColor];
[WebView loadHTMLString:htmlString baseURL:baseURL];
4

2 回答 2

0

你可以做一件事。
放在imageview后面webview并使其webview透明:

WebView.backgroundColor = [UIColor clearColor];
WebView.opaque = NO;

我认为您也可以在 UIWebViews 属性中的 Interface Builder 中进行这些更改。

现在使用您的图像设置图像视图。它将作为背景工作,webview因为它现在是透明的。

于 2013-03-12T04:15:20.217 回答
0

background不支持body属性HTML5。相反,您应该调整它并使用 CSS,以保证它可以移植到不同的 iOS 版本。

这应该可以解决问题:

NSString *htmlString = 
 [[NSString alloc] initWithFormat: 
    @"<html><body style=\"background-image:url(%@)\"></body></html>",url];
于 2013-03-12T02:44:44.920 回答