How to hide the keyboard clipboard programmatically?

Viewed 450

Everytime I click UItextview this clipboard would appear on the bottom, how can I disable it programmatically?

enter image description here

2 Answers

On iPhone you could just set autocorrectionType = .no to completely remove that bar above the keyboard.

On iPad however you should first add these extensions:

extension UITextView {
    func hideSuggestions() {
        // Removes suggestions only
        autocorrectionType = .no
        //Removes Undo, Redo, Copy & Paste options
        removeUndoRedoOptions()
    }
}

extension UITextField {
    func hideSuggestions() {
        // Removes suggestions only
        autocorrectionType = .no
        //Removes Undo, Redo, Copy & Paste options
        removeUndoRedoOptions()
    }
}

extension UIResponder {
    func removeUndoRedoOptions() {
        //Removes Undo, Redo, Copy & Paste options
        inputAssistantItem.leadingBarButtonGroups = []
        inputAssistantItem.trailingBarButtonGroups = []
    }
}

Before:
Before

  1. To just remove the Undo, Redo, Copy and Paste options but show suggestions on top of keyboard, call the function func removeUndoRedoOptions() After

  2. To completely remove the suggestion bar along with Undo, Redo, Copy and Paste options, call the function func hideSuggestions() After

You can disable your textView user interaction:

yourTextView.isUserInteractionEnabled = false

or you can disable textView editability

yourTextView.isEditable = false

UPDATE

If you want to make cursor appears, but do not want this clipboard appears set your textView to become first responder and set your textView inputView with a blank UIView():

textView.becomeFirstResponder()

after that set your textView inputView with a blank UIView():

textView.inputView = UIView()
Related