cordova / phoneGap 這兩個是同一個東西泉孩,開發(fā)網(wǎng)頁用的季率,可以用html
w3school.com.cn 感興趣的可以自己去看看,學習JS的網(wǎng)站
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
//混合開發(fā)
let webView = UIWebView(frame: self.view.bounds)
webView.delegate = self
// let url = NSURL(string: "http://ifeng.com")
// let request = NSURLRequest(URL: url!)
// webView.loadRequest(request)
// let htmlStr = "<h1>這是一個標題</h1>"
// webView.loadHTMLString(htmlStr, baseURL: nil)
//1. 加載本地網(wǎng)頁
let url = NSBundle.mainBundle().URLForResource("index", withExtension: "html")
// let request = NSURLRequest(URL: url!)
// webView.loadRequest(request)
//2.
let data = NSData(contentsOfURL: url!)
webView.loadData(data!, MIMEType: "text/html", textEncodingName: "utf-8", baseURL: NSURL())
self.view.addSubview(webView)
}
//1. 開始加載的時機
//2. 可以過濾網(wǎng)址
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let path = request.URL?.absoluteString
print(path!)
if path!.containsString("baidu.com") {
return false
}
return true
}
func webViewDidStartLoad(webView: UIWebView) {
}
func webViewDidFinishLoad(webView: UIWebView) {
//如果需要操作網(wǎng)頁隔嫡,必須等加載完成
let res = webView.stringByEvaluatingJavaScriptFromString("document.getElementsByTagName('img')")
print(res)
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
}
}