WebView control is to do the Web application development of the most used control, directly within the WebView to specify a page address to access the Web page, but also to implement the Uiwebviewdelegate protocol to implement the corresponding method to control the loading and processing of content. The famous PhoneGap developed the application, its shell important component is also the WebView control.
Add the following code within the Viewdidload method to complete a simple Web page
var WebView = UIWebView (frame:cgrectmake (0, 0, 600, 600))
var url = nsurl (string: "http://www.imoneyfans.com")
Webview.loadrequest (Nsurlrequest (url:url!))
Self.view.addSubview (WebView)
Just like the Loadrequest method used to load the page above to load the page content set by the specified URL object. Method loadhtmlstring is used to load the specified HTML code fragment.
var html = "<section> "
Webview.loadhtmlstring (HTML, Baseurl:nil)
LoadData is also used to load the specified content, such as when a local HTML file is converted to a NSData object and displayed on WebView
var file = Nsbundle.mainbundle (). Pathforresource ("Test", OfType: "HTML")
var url = nsurl.fileurlwithpath (file!)
var data = NSData (contentsofurl:url!)
Webview.loaddata (data, MIMEType: "text/html", Textencodingname: "Utf-8", Baseurl:nil)
for detecting whether the content of a Web page is an interactive type, if you click on an address on the page to bring up the map, you can specify a link, address, phone number (phonenumber), etc. for the data type you want to probe. You can also specify that all types are probed for all, and the phone number can be clicked by default, and the following is the probe phone number
Webview.datadetectortypes = Uidatadetectortypes.phonenumber
There are many other ways, such as
Webview.reload ()
Webview.stoploading ()
Webview.goback ()
Webview.goforward ()
This protocol is implemented Uiwebviewdeleage if more advanced functionality is to be achieved.
Application of WebView in Swift