In my iPad application I have a UIWebView with a youtube video embedded in it. I have matched the UIWebView size and the size of the embedded video as well as made sure that the aspect ratio was correct. I have set the UIWebView background color to clear color with no luck. How can I center the embedded video inside my UIWebView. I also used content mode: center and it doesn't seem to respect it. See the screenshot below:
http://cl.ly/1N3c0d343r3v1i0J1h0d
NSString *video_ID = @"7Ek1QwGp9Tw?rel=0";
NSString *htmlStr = [NSString stringWithFormat:@"<iframe class=\"youtube-player\" type=\"text/html\" width=\"453\" height=\"255\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\"></iframe>",video_ID];
[webView loadHTMLString:htmlStr baseURL:nil];
Any help would be appreciated.
just a wild guess: you need to reset the margins and paddings of your html documents body and the youtube iframe.
edit add something like <html><head><title>.</title><style>body,html,iframe{margin:0;padding:0;}</style></head><body>[YOUR YOUTUBE CODE]</body></html>
Don't use an iframe, just load the video directly in the webview (a webview is basically like a "native" iframe anyway):
NSString *URLString = [NSString stringWithFormat:@"http://www.youtube.com/embed/%@",video_ID];
NSURL *URL = [NSURL URLWithString:URLString];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[webView loadRequest:request];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With