Skip to content

Instantly share code, notes, and snippets.

@sbrocket
Created November 21, 2009 21:59
Show Gist options
  • Select an option

  • Save sbrocket/240302 to your computer and use it in GitHub Desktop.

Select an option

Save sbrocket/240302 to your computer and use it in GitHub Desktop.
- (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