Created
July 14, 2011 14:20
-
-
Save orta/1082537 to your computer and use it in GitHub Desktop.
objective C function to inject CSS from a local file into a webview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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