Created
November 21, 2009 21:59
-
-
Save sbrocket/240302 to your computer and use it in GitHub Desktop.
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)viewDidLoad { | |
| [super viewDidLoad]; | |
| self.webView.backgroundColor = [UIColor clearColor]; | |
| NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; | |
| NSString *cssString = @"body { background-color: transparent; max-width: 320px; margin: 0; padding: 0; }"; | |
| [cssString writeToFile:[documentsPath stringByAppendingPathComponent:@"cache.css"] atomically:YES encoding:NSUTF8StringEncoding error:NULL]; | |
| NSString *youtubeLink = @"http://www.youtube.com/watch?v=nRwRfYDzeqg"; | |
| NSString *youtubeFormat = @"<object width=\"280\"><embed src=\"%@\" type=\"application/x-shockwave-flash\" /></object>"; | |
| NSString *youtubeContent = [NSString stringWithFormat:youtubeFormat, youtubeLink]; | |
| NSString *contentFormat = @"<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"cache.css\" /></head><body>%@</body></html>"; | |
| NSString *content = [NSString stringWithFormat:contentFormat, youtubeContent]; | |
| NSURL *baseURL = [NSURL fileURLWithPath:documentsPath]; | |
| [self.webView loadHTMLString:content baseURL:baseURL]; | |
| debugLog(@"Loading HTML string: %@", content); | |
| } | |
| - (void)webViewDidFinishLoad:(UIWebView *)webView { | |
| CGSize fittedSize = [self.webView sizeThatFits:CGSizeZero]; | |
| self.webView.frame = CGRectIntegral(CGRectMake((CGRectGetWidth(self.view.frame)-fittedSize.width)/2, 0, fittedSize.width, fittedSize.height)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment