Search code examples
iosiphoneswiftuiwebviewvimeo

Vimeo video not fitting properly on UIWebView, swift


I finally managed to show my vimeo video in a UIWebView. The size of the UIWebView is w=280, h = 204.

This is how the video is fitted in the UIWebView:

enter image description here

And then i can drag the video to its place where i would like it to be in the first place when the view is loaded:

enter image description here

This is the code i am using to show the video:

let embedHTML="<html><head><style type=\"text/css\">body {background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><iframe src=\"//player.vimeo.com/video/171151492?autoplay=1&amp;loop=1\" width=\"280\" height=\"204\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>";

webView.delegate = self
let url: NSURL = NSURL(string: "https://player.vimeo.com/video/171151492")!
webView.loadHTMLString(embedHTML as String, baseURL:url )

Solution

  • Your view controller tries to adjust the scroll view insets of UIWebView to your navigation bar.

    You can set your view controller's automaticallyAdjustsScrollViewInsets property to false as below to prevent this:

    self.automaticallyAdjustsScrollViewInsets = false
    

    Or from Interface Builder, untick the “Adjust Scroll View Inset” option of the view controller under Layout section.