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
Your solution won't work because
cssNode.href
should be a URL (i.e. escaped and prefixed with file://
), not a path In the past I've done this by downloading the HTML using an NSURLConnection, and then adding a <style>
tag in the HTML head. Something like:
NSString *pathToiOSCss = [[NSBundle mainBundle] pathForResource:@"reader" ofType:@"css"];
NSString *iOSCssData = [NSString stringWithContentsOfFile:pathToiOSCss encoding:NSUTF8StringEncoding error:NULL];
NSString *extraHeadTags = [NSString stringWithFormat:@"<style>%@</style></head>", iOSCssData];
html = [uneditedHtml stringByReplacingOccurrencesOfString:@"</head>" withString:extraHeadTags];
[webView loadHTMLString:html baseURL:url];