1. 程式人生 > >IOS控制元件-UIWebView

IOS控制元件-UIWebView

簡單的UIWebView操作、

//載入網頁
        let webView1 = UIWebView(frame: CGRect(x: 0, y: 20, width: 400, height: 300))
        let request = URLRequest(url: URL(string: "https://www.baidu.com")!)
        webView1.loadRequest(request)
        self.view.addSubview(webView1)
        
        //載入本地html
        let webView2 = UIWebView(frame: CGRect(x: 0, y: 350, width: 400, height: 300))
        let html = "<font color='blue'>Hello!!</font>,<B>Xcode</B> and <i>Swift</>"
        webView2.loadHTMLString(html, baseURL: nil)
        self.view.addSubview(webView2)