3

I've been trying to align my embedded YouTube video inside a UIWebView but the margin and padding just won't disappear.

enter image description here

I tried to get rid of it by using following code:

let padding = "document.body.style.margin='0';document.body.style.padding = '0'"
    webView.stringByEvaluatingJavaScriptFromString(padding)

It's still not aligning correctly. I'm embedding the video using

    let embededHTML = "<html><body><iframe src=\"http://www.youtube.com/embed/W7qWa52k-nE?playsinline=1\" width=\"\(width)\" height=\"\(height)\" frameborder=\"0\" allowfullscreen></iframe></body></html>"
    webView.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL)

Can someone tell me what could be wrong? I'm pretty sure there is nothing wrong with the webView positioning. This question contains answers to a similar issue but isn't that what I'm doing with JavaScript? If not, How do I add CSS to my HTML string?

Community
  • 1
  • 1
Percolator
  • 513
  • 5
  • 25
  • 1
    Use safari's developer tools to look and see where the padding/margin is coming from while you have your app running in simulator or on iOS device with app launched from xcode. Your js looks correct to me. – Mark Sep 22 '15 at 21:30

0 Answers0