我有一个网页视图,我想填写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. } }
解决方法
设置缩放以适合视图边界.试试这个:
self.webView.frame = self.view.bounds self.webView.scalesPageToFit = true
希望这可以帮助.. :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。