OStack程序员社区-中国程序员成长平台

标题: IOS UIWebView 没有加载完整的网站 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:13
标题: IOS UIWebView 没有加载完整的网站

我正在学习 iOS。我正在尝试在 UIWebView 中加载网站。网页正在加载,但 Web View 未加载整个网站。相反, WebView 会加载网站的部分页面。这是代码 我做错了什么??

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



Best Answer-推荐答案


选择-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)

附加 reference1 , reference2

这里我附上了 sample project

项目输出

enter image description here

关于IOS UIWebView 没有加载完整的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32390336/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4