我是IOS Swift的新手,需要一些帮助。我已经关注了本论坛中发现的其他例子,但没有运气。 无论我做什么,网页都不会扩展以适应UIwebview。
请帮忙。
以下是代码
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "https://www.bbc.co.uk");
let requestObj = NSURLRequest(URL: url!);
webView.scalesPageToFit = true
webView.contentMode = UIViewContentMode.ScaleAspectFit
webView.delegate = self;
webView.frame = self.view.bounds
webView.stringByEvaluatingJavaScriptFromString("document.body.style.zoom= 5.0;")
webView.loadRequest(requestObj);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidFinishLoad(webView: UIWebView) {
let zoom = webView.bounds.size.width / webView.scrollView.contentSize.width
webView.scrollView.setZoomScale(zoom, animated: true)
}
}