I am attempting to inject a local CSS file to override the styling of a webpage. The webpage is presented in a UIWebView
container in iOS. However I am not able to get my code to work. See the snippet of my delegate method below. This code runs (I can see the NSLog
message) but I do not see the results of it's execution on the page.
I know it can't be the CSS I wrote because in this case I took the pages own CSS file and simply changed some colors. (In order to test this method)
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *cssPath = [path stringByAppendingPathComponent:@"reader.css"];
NSString *js = [NSString stringWithFormat:@"var headID = document.getElementsByTagName('head')[0];var cssNode = document.createElement('link');cssNode.type = 'text/css';cssNode.rel = 'stylesheet';cssNode.href = '%@';cssNode.media = 'screen';headID.appendChild(cssNode);", cssPath];
[webView stringByEvaluatingJavaScriptFromString:js];
NSLog(@"webViewDidFinishLoad Executed");
}