Question

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.

No correct solution

OTHER TIPS

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top