UIWebView不适合设备屏幕

时间:2015-01-28 05:12:16

标签: ios swift uiwebview

我有一个网页视图,我想填写iDevice的全屏。我把它放在视图中心设置为中心并与容器边缘齐平。然而,当我加载应用程序时,视图比它运行的模拟iPhone大。我做了一些搜索,一些建议自动布局,这已经应该是视图的中心。我发现的另一件事是通过代码设置大小。

self.webView.frame = self.view.bounds

我甚至将应用程序从通用应用程序更改为iPhone,对布局没有影响。

完整来源:

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.
    }


}

2 个答案:

答案 0 :(得分:10)

设置缩放以适合视图边界。试试这个:

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

希望这会有所帮助.. :)

答案 1 :(得分:2)

如果您不想以编程方式设置此项 一种方法是以这种方式将此4约束添加到webView:

enter image description here

这适合我。

相关问题