Blog of Geof

Friday, Aug. 17th

Custom Input View on iOS: Hiding UITextInputAssistantItems

I've been working on a small app with a custom inputView and a custom inputAccessoryView.

One issue I experienced on iPad was this goofy bar sandwiched between both custom input views (pictured below).

Screenshot of my app with a goofy UITextInputAssistantItem bar

After some searching, I found out that those are UITextInputAssistantItems.

The app I’m working on has a unique and minimal amount of text input that is required. It doesn’t make sense to have undo, redo or copy & paste taking up so much screen real-estate.

I discovered that if you create a custom UITextField class and set both of the leadingBarButtonGroups and trailingBarButtonGroups to an empty array the UITextInputAssistantItem bar will disappear.

class CustomTextField: UITextField {

    init(frame: CGRect) {

        super.init(frame: frame)

        // remove undo/redo and copy/paste item bar on ipad
        inputAssistantItem.leadingBarButtonGroups = []
        inputAssistantItem.trailingBarButtonGroups = []
    }
}