4

I'm having a UIWebView with the following code:
<iframe class="youtube-player" type="text/html" width="320" height="180" src="http://www.youtube.com/embed/OsSZ4u7Sz6s" frameborder="0"></iframe>

The thing is the the video preview is offest by a few pixels (see image)

I checked with recursiveDescription The UIWebView itself is in the right place (0,0,320,180)

How can I make it tight?
enter image description here

Edit:
Apparently it happens on Vimeo iframe as well -so the problem is not youtube specific but iframe specific

Boaz
  • 4,864
  • 12
  • 50
  • 90

2 Answers2

4

Margins and paddings needs to be reseted.

NSString *yourHtml = @"<html><head><title>.</title><style>body,html,iframe{margin:0;padding:0;}</style></head><body><iframe width=\"100%%\"  height=\"250\" src=\"http://www.youtube.com/embed/OsSZ4u7Sz6s\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
[self.webView loadHTMLString:yourHtml baseURL:nil];

If you want more flexibility with your videos you can take a look at my answer here that uses a 3rd party class.

Community
  • 1
  • 1
Segev
  • 19,035
  • 12
  • 80
  • 152
  • thanks! Just fix you code yourHtml/embedHTML in case someone copy pastes without noticing :) – Boaz Dec 03 '14 at 08:41
0

Your webView is adding the margins because you have no body in your html. Just add a body with no margins:

<body style='margin:0px;'><iframe ...></iframe></body>

And that's it.

However, if you allow me to say it, it looks nice with a white margin :D you would just need to adjust the size of the iframe.

Hope it helps!

Iree
  • 358
  • 3
  • 13