2010-01-15 97 views
1

在此先感謝您發送回答........ 我是iphone開發的初學者。如何在iphone中設置HTML頁面的背景圖像

我嘗試了最後2天在iphone中設置UIWebView的背景圖像,但我不能。 Becoze我不知道如何從項目目錄中獲取圖像的正確路徑和正確的語法。

回答

1

使用此代碼加載HTML與背景圖像。

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

     NSString *size = [@"100%25" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 





     NSString *contentHtml = [NSString stringWithFormat:@"<html>\ 
           <head>\ 
           <style type=\"text/css\">\ 
           html {height:%@;}\ 
           body {height:%@; margin:0; padding:0; color:white; font-size:40px;}\ 
           #bg {position:fixed; top:0; left:0; width:%@; height:%@;}\ 
           #content {position:relative; z-index:1;}\ 
           </style>\ 
           </head>\ 
           <body>\ 
           <div id=\"bg\"><img src=\"%@\" width=\"%@\" height=\"%@\"></div>\ 
           <div id=\"content\"><font color=\"#DAF899\" size=\"+4\"><b>%@</b></font><p>%@</p></div>\ 
           </body>\ 
           </html>", size, size, size, size, url, size, size, self.navigationItem.title, content]; 






     [webView loadHTMLString:contentHtml baseURL:nil]; 

希望這會有所幫助。

0

UIWebView顯示HTML,要在Web視圖中顯示圖像,您需要提供適當的HTML內容到loadHTMLString:baseURL:loadData:MIMEType:textEncodingName:baseURL:

1
  1. 創建一個UIImageView並加載圖像。
  2. 創建一個UIWebView並將背景顏色設置爲[UIColor clearColor]。
  3. 將UIWebView作爲子視圖添加到UIImageView。
+0

我認爲這是[UIColor clearColor] – NWCoder 2010-01-20 18:15:44

+0

是的。謝謝。 :) – 2010-01-20 19:27:27