簡體   English   中英

HTML身體背景圖片在iOS 5中不起作用

[英]Html body background image doesn't work in ios 5

此代碼在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];

HTML5不支持body background屬性。 相反,您應該對其進行調整並使用CSS,以確保它可以在不同的iOS版本中移植。

這應該可以解決問題:

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

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

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

我認為您也可以在UIWebViews屬性的Interface Builder中進行這些更改。

現在,將imageview設置為您的圖像。 由於它現在是透明的,因此它將作為webview的背景。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM