cordova / phoneGap 这两个是同一个东西,开发网页用的,可以用html
w3school.com.cn 感兴趣的可以自己去看看,学习JS的网站
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
//混合开发
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. 加载本地网页
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. 可以过滤网址
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) {
//如果需要操作网页,必须等加载完成
let res = webView.stringByEvaluatingJavaScriptFromString("document.getElementsByTagName('img')")
print(res)
}
func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
}
}
网友评论