ios开发app嵌入网页/webview

  • 系统:Mac OS X 10.14.5
  • 工具:XCode 10.3
  • 语言:swift

 

//
//  ViewController.swift
//  demo
//
//  Created by tanao on 2019/9/18.
//  Copyright © 2019 eatm. All rights reserved.
//

import UIKit
import WebKit    //导入

var webview = WKWebView()    //全局变量

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        //创建窗口
        let webview = WKWebView(frame: CGRect(x:0, y:0, width:self.view.frame.width, height:self.view.frame.height))
        
        //加载网页
        let url = URL(string: "https://www.baidu.com")!
        webview.load(URLRequest(url: url))
        
        //显示视图
        self.view.addSubview(webview)
    }
}

 

发表评论

电子邮件地址不会被公开。