Adam Adam - 2 months ago 9
Swift Question

Xcode WebApp - Not Centered when launched on iPhone/Safari

I'm doing my first Xcode WebApp - below is the View Controller:

//
// ViewController.swift
// iOS8SwiftWebViewTutorial
//
// Created by Administrator on 26/09/2016.
// Copyright © 2016 Administrator. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

let url = "https://japanese.dating"

override func viewDidLoad() {
super.viewDidLoad()

let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.loadRequest(request)
}

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

@IBOutlet weak var webView: UIWebView!

}


It launches on the Simulator and my physical iphone.

The only issue is what ever site I put into the code - even sites like www.google.com I find its not centered.

enter image description here

Thanks-you :)

Answer

if the webView should fill the screen then you can use:

webView.frame = self.view.frame

place that in your viewDidLoad method.

Comments