- May 27, 2025
- Mins Read
Otafuku provides utility classes to use WKWebView.
WebViewUIController
to handle WKUIDelegate methods by presenting an alert as usual browsers do.WebViewPropertyObserver
to notify WKWebView property value change via a registered closure and Swift enum. With this class, no KVO code is needed to know WKWebView property value change.WebViewUIController
handles WKUIDelegate.
As shown below, simply declare a property of WebViewUIController
and set it to WKWebView.UIDelegate in UIViewController.viewDidLoad.
class ViewController: UIViewController {
let uiDelegate = WebViewUIController()
override func viewDidLoad() {
super.viewDidLoad()
webView.UIDelegate = uiDelegate
}
}
WebViewPropertyObserver
notifies WKWebView property value change.
As shown below, declare a property of WebViewPropertyObserver
to retain its object throughout the ViewController’s life cycle.
To initialize, pass a WKWebView object and a closure handling WKWebView’s property change.
class ViewController: UIViewController {
@IBOutlet var progressView: UIProgressView!
@IBOutlet var backItem: UIBarButtonItem!
@IBOutlet var forwardItem: UIBarButtonItem!
var propertyObserver: WebViewPropertyObserver?
override func viewDidLoad() {
super.viewDidLoad()
propertyObserver = WebViewPropertyObserver(webView: webView, handler:handleWebViewPropertyChange)
}
func handleWebViewPropertyChange(property: WebViewPropertyObserver.WebViewProperty) {
switch property {
case .Title(let title):
navigationItem.title = title
case .URL(let URL):
// do something with URL
break
case .CanGoBack(let canGoBack):
backItem.enabled = canGoBack
case .CanGoForward(let canGoForward):
forwardItem.enabled = canGoForward
case .EstimatedProgress(let progress):
progressView.progress = progress
case .Loading(let loading):
// do something with loading
break
case .HasOnlySecureContent(let secureContent):
// do something with secureContent
break
}
}
}
platform :ios, ‘8.0’
use_frameworks!
pod ‘Otafuku’
Light and scrollable view controller for tvOS to present blocks of text Description TvOSTextViewer is a view controller to present ...
TvOSSlider is an implementation of UISlider for tvOS. Description and usage TvOSSlider palliates missing an implementation of UISlider for tvOS as part ...
TvOSScribble, based on CoreML, mitigates the lack of a physical numpad area in Siri Remote implementing a handwriting gesture recognizer. ...
PIN keyboard for tvOS Description TvOSPinKeyboard is a view controller that allows easily asking for PIN codes in tvOs Requirements ...
📺 A tvOS button which truncates long text with '... More'. The TvOSMoreButton is a simple view which aims to ...