user2462805
user2462805

Reputation: 1069

UIWebView centring page and allow navigation

I managed to have a website loaded in my UIWebView but I can't manage to center it. I also would like to be able to "navigate" into the website. What am I doing wrong ?

here's the code :

 import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var WebView: UIWebView!



    var URLPath = "http://google.fr"

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

        WebView.scalesPageToFit = true
        WebView.keyboardDisplayRequiresUserAction = true


        loadAdressURL()
    }

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

    func  loadAdressURL () {
        let requestURL = NSURL(string:URLPath)
        let request = NSURLRequest(URL: requestURL)

        WebView.loadRequest(request)
    }

}

And here's the IOS Simulator :

Simulator

Rob.

Upvotes: 1

Views: 2027

Answers (1)

Rein rPavi
Rein rPavi

Reputation: 3396

Add this

override func viewDidAppear(animated: Bool) {
       WebView.frame = UIScreen.mainScreen().bounds
        WebView.center = self.view.center
    }

Upvotes: 3

Related Questions