Pictures in HTML files in iOS app -


i'm new ios development , i'm having issue displaying image inside html file. display html file in webview not images inside it. have added png files same folder retrieve html file neither the

background-image: url(bg1.png);

nor

<img src="logo.png"/>

seem work.

i think i've worked out way add external files ios app because set pictures background webview, issue html file not display it. tested file in several browsers , there's no problem.

am writing paths wrong or simpler rookie mistake?

thanks in advance.

using relative paths or file: paths refer images not work uiwebview. instead have load html view correct baseurl:

nsstring *path = [[nsbundle mainbundle] bundlepath]; nsurl *baseurl = [nsurl fileurlwithpath:path]; [webview loadhtmlstring:htmlstring baseurl:baseurl]; 

you can refer images this:

<img src="myimage.png"> 

or within css this:

background-image: url(loading.gif) 

example :

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

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -