Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView does not fit to device screen

I have a web view that I want to fill the full screen of a iDevice. I placed it in the center of the view set to be center and flush with the edge of the container. However when I load the app, the view is larger than the emulated iPhone it is running in. I have done some searching and some suggest auto layout, which is already supposed to be centering the view. Another thing I found was to set the size though code.

self.webView.frame = self.view.bounds

I even changed the app from a universal app to just iPhone, with no effect on the layout.

Full source:

class ViewController: UIViewController {

    @IBOutlet weak var webView: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        self.webView.frame = self.view.bounds

        webView.frame = self.view.bounds
        var uri = NSURL(string:"http://google.com")
        var req = NSURLRequest(URL: uri)
        webView.loadRequest(req)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
like image 737
QueueHammer Avatar asked Jan 28 '15 05:01

QueueHammer


People also ask

What is UIWebView on Apple Iphone?

A view that embeds web content in your app.

What is use of UIWebView or WKWebView?

A WKWebView object is a platform-native view that you use to incorporate web content seamlessly into your app's UI. A web view supports a full web-browsing experience, and presents HTML, CSS, and JavaScript content alongside your app's native views.

What does UI WebView mean?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application. Android is powered by Chrome. Mobile Safari UIWebView.

How can I clear the contents of a UIWebView WKWebView?

To clear old contents of webview With UIWebView you would use UIWebViewDelegate 's - webViewDidFinishLoad: .


1 Answers

Set the scaling to fit the view bounds. Try this:

self.webView.frame = self.view.bounds
self.webView.scalesPageToFit = true

Hope this helps.. :)

like image 184
Rashad Avatar answered Sep 23 '22 12:09

Rashad