Skip to content

Instantly share code, notes, and snippets.

@orta
Created July 14, 2011 14:20
Show Gist options
  • Save orta/1082540 to your computer and use it in GitHub Desktop.
Save orta/1082540 to your computer and use it in GitHub Desktop.
objective C function to inject CSS from a local file into a webview
-(void)injectCSS {
NSString *path = [[NSBundle mainBundle] pathForResource:@"override" ofType:@"css"];
NSString * cssString = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil];
cssString = [cssString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
cssString = [cssString stringByReplacingOccurrencesOfString:@"\"" withString:@"'"];
NSString * js = [NSString stringWithFormat:@"$('head').append('<style>%@</style>');", cssString];
[webView stringByEvaluatingJavaScriptFromString:js];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment