Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get rid of white border around youtube video embedded in UIWebView?

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.

like image 892
kyleplattner Avatar asked Feb 02 '12 17:02

kyleplattner


2 Answers

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>

like image 189
roman Avatar answered Nov 09 '22 01:11

roman


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];
like image 32
Nick Lockwood Avatar answered Nov 09 '22 01:11

Nick Lockwood