How to include CSS resource in programmatically generated HTML for iPhone UIWebView?

I am generating HTML programmatically and want to link to a CSS file that I have included in my Resources folder. I am using baseURL from nil and my CSS file is at the top level of the project file, but this “link” definitely doesn’t work (i.e. the CSS file does not explicitly load / detect when the UIWebView displays HTML).

Can this be done? Or do I need to host a CSS file somewhere on the Internet and link it using a URL? (I see the advantage of this - using the application to change its style without redistributing the application).

thank

+1
source share
2 answers

Thanks everyone! Here is what I did, works great.

NSBundle *bundle = [NSBundle mainBundle];
NSURL *resourceBaseURL = [NSURL fileURLWithPath:[bundle bundlePath]];
[self.webView loadHTMLString:htmlString baseURL:resourceBaseURL];
+5

URL- :

NSBundle *bundle = [NSBundle mainBundle];
NSURL *baseURL = [NSURL fileURLWithPath:[bundle bundlePath]];
+1

Source: https://habr.com/ru/post/1794648/


All Articles