How to remove, update, or replace the WKWebView inputAccessoryView

Many others, including myself, have been trying to safely modify the WKWebView.inputAccessoryView. Now in iOS 13+, you can do it!

TL;DR; The WebKit team update the code, Apple updated their dependency in iOS 13.

Swift code sample:

import WebKit

class RichEditorWebView: WKWebView {

    var accessoryView: UIView?

    override var inputAccessoryView: UIView? {
        // remove/replace the default accessory view
        return accessoryView
    }
}

In another class somewhere:

// set accessory view to replace it, if left untouched, then it will be removed
let webView = RichEditorWebView()
webView.accessoryView = SomeAwesomeInputAccessoryView()

Because WebKit is a library that iOS uses (like SQLite), I assumed that Apple would update that dependency as well for iOS 13, since the change was resolved around June 2019.

References:
  1. https://trac.webkit.org/changeset/246229/webkit#file1
  2. https://bugs.webkit.org/show_bug.cgi?id=198631
It was too difficult to find the answer, so I'm posting in multiple places to make it easier to find for the next person.

My original SO answer here: https://stackoverflow.com/a/58001395/344591
Working code example: https://github.com/cbess/RichEditorView/commits/master

Comments

Popular posts from this blog

Text Sherlock the OpenGrok alternative (Source Code Search Engine)

Python SUDS with Windows Authentication (SOAP)