[英]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.