Skip to content

Commit

Permalink
Block based UIWebView added
Browse files Browse the repository at this point in the history
  • Loading branch information
cemolcay committed Dec 23, 2014
1 parent cd2b122 commit 8f6089f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Binary file not shown.
42 changes: 42 additions & 0 deletions CEMKit-Swift/CEMKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,45 @@ class BlockButton: UIButton {



// MARK: - UIWebView

class BlockWebView: UIWebView, UIWebViewDelegate {

var didStartLoad: ((NSURLRequest) -> ())?
var didFinishLoad: ((NSURLRequest) -> ())?
var didFailLoad: ((NSURLRequest, NSError) -> ())?

var shouldStartLoadingRequest: ((NSURLRequest) -> (Bool))?

override init(frame: CGRect) {
super.init(frame: frame)
delegate = self
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}


func webViewDidStartLoad(webView: UIWebView) {
didStartLoad? (webView.request!)
}

func webViewDidFinishLoad(webView: UIWebView) {
didFinishLoad? (webView.request!)
}

func webView(webView: UIWebView, didFailLoadWithError error: NSError) {
didFailLoad? (webView.request!, error)
}

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if let should = shouldStartLoadingRequest {
return should (request)
} else {
return true
}
}

}

0 comments on commit 8f6089f

Please sign in to comment.