简体   繁体   中英

IOS UIWebView is not loading the full website

i am learning iOS. i am trying to load a website in the UIWebView. The webpage is loading but the web view is not loading the full website. Instead the web view loads partial page of the website. Here is the code what have i done wrong??

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

choice -1

 webView.scalesPageToFit = true

if it is not work try choice no -2

choice -2

 webView.frame = UIScreen.mainScreen().bounds
 webView.center = self.view.center
 webView.scalesPageToFit = true

choice -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)

additional reference1 , reference2

here I attached the sample project

the project output

在此处输入图片说明

Nothing is wrong at all. There is no problem whatsoever with the code. I'm not sure why you split the screenshot but the website has a mobile version and that's what your seeing. They purposely made it look like that. They scale it to the devices width and remove elements if needed.

代码中提到的站点

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM