Reputation: 7789
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.
Upvotes: 2
Views: 3366
Reputation: 8114
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.
Upvotes: 2
Reputation: 1680
Upvotes: 1
Reputation: 5064
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:
.
Upvotes: 0