这是我的代码:
//MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
loadWebView()
}
//MARK: - Methods
func loadWebView() {
let url = URL(string: "http://www.lipsum.com/")
//(URL(string: Constant.MedataApi.BaseUrl)?.appendingPathComponent(Constant.termsAndConditions))!
let request = NSURLRequest.init(url: url! as URL)
webView.loadRequest(request as URLRequest)
//webView.layer.borderWidth = 1.0
//webView.layer.borderColor = UIColor.red.cgColor
}
//MARK: - IBActions () -
@IBAction func cancelButtonClicked(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
答案 0 :(得分:0)
假设您有两个View Controller,一个是FirstViewController,另一个是SecondViewController(webView)。
在Main.storyboard中,选择FirstViewController并将其嵌入为NavigationController。
现在将一个Storyboard ID分配给Main.storyboard中的SecondViewController,假设Storyboard ID为“SecondVC”。
在FirstViewController.swift中添加按钮操作的代码:
let firstController = self.storyboard?.instantiateViewController(withIdentifier: "SecondVC") as! SecondViewController
navigationController?.pushViewController(firstController, animated: true)
然后在SecondViewController.swift文件中添加webView代码。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let url = URL(string: "http://www.lipsum.com/")
let request = URLRequest(url: url!)
webView.loadRequest(request)
webView.scalesPageToFit = true
}