Timo Cengiz Timo Cengiz - 1 year ago 73
iOS Question

Get the CORRECT size of an UIWebView after it has loaded, swift

I am having so much trouble showing a simple vimeo videon on my UIWebView. I have come so far that i can show the video and it is able to play in fullscreen mode.

The problem is that the video is not fitting properly inside my UIWebView.

In storyboard the UIWebView is set to have 560 in width and 105 in height. This is obviously changed in runtime since it resizes to fit different screens.

This becomes a problem because in the html embedded code that is needed to show the video is where you specify the videos size such as width and height.

So now for my question.. How can i get the correct size of my UIWebView after it has been loaded and all so i can match it with the videos frames?

Answer Source

If your web view fills the whole view you can get the views frame and get the width and height from there.

Call this code in viewDidAppear():

let height = view.frame.height
let width = view.frame.width
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download