我正在学习iOS。我想在UIWebView中加载一个网站。网页正在加载,但网页视图未加载整个网站。而是Web视图加载网站的部分页面。这是代码 我做错了什么?
import UIKit
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.
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
webView.frame = self.view.frame
let url = "http://www.tradiestart.com.au"
let requestUrl = NSURL(string: url)
let request = NSURLRequest(URL: requestUrl!)
webView.loadRequest(request)
webView.scrollView.scrollEnabled = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:1)
选择-1
webView.scalesPageToFit = true
如果不起作用,请尝试选择否-2
选择-2
webView.frame = UIScreen.mainScreen().bounds
webView.center = self.view.center
webView.scalesPageToFit = true
选择-3
webView.frame =CGRectMake(0,0, self.view.frame.size.width , self.view.frame.size.height)
or
webView.frame =CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height)
这里我附上了sample project
项目输出
答案 1 :(得分:1)