iOS開發——UI篇Swift篇&UIWebView

來源:互聯網
上載者:User

標籤:

 

 

UIWebView

 

  1     //返回按鈕事件  2     @IBAction func backButtonClick()  3     {  4         self.navigationController?.popViewControllerAnimated(true)  5     }  6       7       8     override func viewDidLoad() {  9         super.viewDidLoad() 10          11         titleLabel.text = titleString 12          13          14         // Do any additional setup after loading the view. 15          16          17         //建立UIWebView 18         var aWebView:UIWebView = UIWebView(frame: CGRectMake(0, 65, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height-65)) 19          20          21         //添加到視圖上 22         self.view.addSubview(aWebView) 23          24         //網址字串 25         var webString = "http://www.iphonetrain.com" 26          27         //通過String類型初始化NSURL對象 28         var url:NSURL! = NSURL(string: webString) 29          30         //通過NSURL對象初始化NSURLRequest 31         var request:NSURLRequest = NSURLRequest(URL: url) 32          33         //webView載入網頁 34         aWebView.loadRequest(request) 35          36          37         //設定網頁壓縮,全螢幕顯示 38         aWebView.scalesPageToFit = true 39          40          41         var htmlString:String = "<font face=黑體 size=7 color=\"red\">無限互聯3G學院</font>" 42          43         //baseURL賦值一個資源css的路徑,可以用網路路徑使用網路上的CSS 44 //        aWebView.loadHTMLString(htmlString, baseURL: nil) 45          46          47         //定義一個常量路徑 48         let wordPath:String? = NSBundle.mainBundle().pathForResource("SwiftIntroduction", ofType: "docx") 49      50         //通過String類型初始化NSURL對象 51         let wordURL:NSURL! = NSURL(string: wordPath!) 52          53         //通過NSURL對象初始化NSURLRequest 54         let wordRequest:NSURLRequest = NSURLRequest(URL: wordURL) 55          56         //載入 57 //        aWebView.loadRequest(wordRequest) 58          59          60         //設定網頁視圖識別的內容 61         aWebView.dataDetectorTypes = UIDataDetectorTypes.Address 62          63     } 64  65     override func didReceiveMemoryWarning() { 66         super.didReceiveMemoryWarning() 67         // Dispose of any resources that can be recreated. 68     } 69      70  71     /* 72     // MARK: - Navigation 73  74     // In a storyboard-based application, you will often want to do a little preparation before navigation 75     override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { 76         // Get the new view controller using segue.destinationViewController. 77         // Pass the selected object to the new view controller. 78     } 79     */ 80      81     // MARK: - UIWebViewDelegate 82      83     func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool 84     { 85         if navigationType == UIWebViewNavigationType.LinkClicked 86         { 87              88         } 89          90         return true 91     } 92      93     func webViewDidStartLoad(webView: UIWebView) 94     { 95         //開始載入 96     } 97      98     func webViewDidFinishLoad(webView: UIWebView) 99     {100         //載入成功結束101     }102     103     func webView(webView: UIWebView, didFailLoadWithError error: NSError)104     {105         //載入失敗106     }

 

 

iOS開發——UI篇Swift篇&UIWebView

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.