Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load UIWebView with a CSS local file

I'm looking for a way to load my UIWebView with a local CSS file that should affect on the UIWebView's loadRequest.

For the clearness: I have an UIWebView that I loadRequest it with a website url. I also have a local CSS file that should affect this loadRequest url.

I want to load this CSS file onto the UIWebView.

Thanks,

like image 535
jkigel Avatar asked Jul 29 '11 12:07

jkigel


1 Answers

This stackoverflow question appears to have one or two answers that may help you.

You need to load the local CSS (using a method not unlike @Shrey uses, but looking for your CSS file), and somehow inject it into the page, and the only way appears to be to use:

[webview stringByEvaluatingJavaScriptFromString:someJavascriptToInjectCSS];

and some clever Javascript to modify the page to add the CSS in.

Hope this helps point you in the right direction. I have used this method to inject stuff into pages, so it does work, but I don't know Javascript well enough to write the code to inject your CSS into the page.

like image 174
iandotkelly Avatar answered Nov 14 '22 23:11

iandotkelly