首页 > 代码库 > UIWebView

UIWebView

//

//  WebViewController.swift

//  UIControlDemo

//

//  Created by on 14/12/3.

//  Copyright (c) 2014 马大哈. All rights reserved.

//

 

import UIKit

 

class WebViewController: BaseViewController ,UIWebViewDelegate{

    var web:UIWebView?

    override func viewDidLoad() {

        super.viewDidLoad()

        

        self.title = "WebView"

 

        web = UIWebView(frame: CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height))

        web?.backgroundColor = .whiteColor()

        web?.delegate = self

        web?.scalesPageToFit = true

        self.view.addSubview(web!)

        

        let stringUrl = "http://www.baidu.com"

        let url = NSURL(string: stringUrl)

        let urlRequest = NSURLRequest(URL: url!)

        web?.loadRequest(urlRequest)

 

    }

    

    func webView(webView: UIWebView, didFailLoadWithError error: NSError) {

        

        println("didFailLoadWithError")

        

    }

    

    func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {

        

        println("\(request)")

        

        return true

    }

    

    func webViewDidFinishLoad(webView: UIWebView) {

        println("webViewDidFinishLoad")

        

    }

    

    func webViewDidStartLoad(webView: UIWebView) {

        

        println("webViewDidStartLoad")

    }

    

    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

 

    }

 

}

 

UIWebView