IOS UIWebView 未加载完整网站
IOS UIWebView is not loading the full website
我正在学习iOS。我正在尝试在 UIWebView 中加载一个网站。网页正在加载,但网络视图未加载完整网站。相反,网络视图加载网站的部分页面。这是代码
我做错了什么??
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.
}
}
选择-1
webView.scalesPageToFit = true
if it is not work try choice no -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
项目产出
完全没有问题。代码没有任何问题。我不确定您为什么拆分屏幕截图,但该网站有移动版本,这就是您所看到的。他们故意让它看起来像那样。他们将其缩放到设备宽度并在需要时删除元素。
我正在学习iOS。我正在尝试在 UIWebView 中加载一个网站。网页正在加载,但网络视图未加载完整网站。相反,网络视图加载网站的部分页面。这是代码 我做错了什么??
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.
}
}
选择-1
webView.scalesPageToFit = true
if it is not work try choice no -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
项目产出
完全没有问题。代码没有任何问题。我不确定您为什么拆分屏幕截图,但该网站有移动版本,这就是您所看到的。他们故意让它看起来像那样。他们将其缩放到设备宽度并在需要时删除元素。