views:

253

answers:

3

Thanks in advance for sending answer to me........ Im the beginner in iphone development.

I tried last 2 days to set background image in UIWebView in iphone.But i can't. Becoze i doesn't know how to take(proper path) of the image from of project directory and proper syntax of that.

A: 

The UIWebView displays HTML, to display an image in the web view you would need to supply proper HTML content to loadHTMLString:baseURL: or loadData:MIMEType:textEncodingName:baseURL:.

Greg Martin
A: 
  1. Create a UIImageView and load your image.
  2. Create a UIWebView and set the background color to [UIColor clearColor].
  3. Add the UIWebView as a subview to the UIImageView.
David Sowsy
I think it's [UIColor clearColor]
NWCoder
Yup. Thanks. :)
David Sowsy
A: 

Use this code to load the html with a background image.

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];

Hope this helps,

Thanks,

Madhup

Madhup