Created
February 24, 2013 02:45
-
-
Save jkatzer/5022357 to your computer and use it in GitHub Desktop.
lazy html/css background color passing to uiwebview. don't think this is necessary but hate for the code to go to waste. i wouldn't use it in a real project, but i just love playing with communication between uiwebview and the document it contains.
This file contains 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)webViewDidFinishLoad:(UIWebView *)webView { | |
NSString* backgroundColorString = [webView stringByEvaluatingJavaScriptFromString:@"document.body.style.background"]; | |
if ([backgroundColorString length] != 0) { | |
if ([backgroundColorString rangeOfString:@"rgb("].location == NSNotFound) { | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@"rgb(" withString:@""]; | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@")" withString:@""]; | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
NSArray* colors = [backgroundColorString componentsSeparatedByString:@","]; | |
webView.backgroundColor = [UIColor colorWithRed:[colors[0] floatValue] green:[colors[1] floatValue] blue:[colors[2] floatValue] alpha:1.0]; | |
} else if ([backgroundColorString rangeOfString:@"rgba("].location == NSNotFound) { | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@"rgba(" withString:@""]; | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@")" withString:@""]; | |
backgroundColorString = [backgroundColorString stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
NSArray* colors = [backgroundColorString componentsSeparatedByString:@","]; | |
webView.backgroundColor = [UIColor colorWithRed:[colors[0] floatValue] green:[colors[1] floatValue] blue:[colors[2] floatValue] alpha:[colors[3] floatValue]]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment