我有一个 WebView ,我想填满 iDevice 的整个屏幕。我把它放在 View 的中心,设置为居中并与容器的边缘齐平。但是,当我加载该应用程序时,该 View 比运行它的模拟 iPhone 大。我进行了一些搜索,有些人建议使用自动布局,这应该已经使 View 居中。我发现的另一件事是通过代码设置大小。
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.
}
}
最佳答案
设置缩放以适合 View 边界。试试这个:
self.webView.frame = self.view.bounds
self.webView.scalesPageToFit = true
希望这会有所帮助..:)
关于ios - UIWebView 不适合设备屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28185080/