I have a web view in an application that downloads an html fragment from a server that includes text and images. I wrap this in a small html and put it in a web view as follows:
NSString *cssPath = [[NSBundle mainBundle] pathForResource:@"style" ofType:@"css"]; NSString *cssLink = [NSString stringWithFormat:@"<link href='file://%@/' type='text/css' rel='stylesheet'/>", cssPath]; NSString *html = [[NSString stringWithFormat:@"<html><head><title></title><meta charset='UTF-8' />%@</head><body>%@</body></html>", cssLink, htmlContent] retain]; [myWebView loadHTMLString:html baseURL:currentURL];
Is there a way to fix the above code so that the link to the local stylesheet works?
I can load the stylesheet without problems if I change the base url to the local application resource file, but this will break the links to images inside the html downloaded from the server.
I could also include the contents of the stylesheet directly in html, but would prefer not to do this for a number of reasons.
Thanks.
source share