69

I'm trying to update an app for iOS8, which has a chat interface, but the new Quicktype keyboard hides the text view, so I would like to turn it off programmatically or in interface builder.

Is it possible somehow or only the users can turn it off in the device settings?

I know there is a question/answer which solves this problem with a UITextfield, but I need to do it with a UITextView.

9
  • 1
    I don't know whether you can or not, but it doesn't seem like a good idea anyway. I use an app that does something similar on Android, and it's really frustrating. I think it's better to work around it to allow the user to decide whether they want those suggestions there or not.
    – user377628
    Sep 20, 2014 at 17:18
  • 1
    @Hassan My problem is, that it destroys my UI, so I wanna hide/disable any suggestions.
    – rihekopo
    Sep 20, 2014 at 17:29
  • Yes, but wouldn't it be better if you could move the text view up to accommodate the keyboard, rather than hide the suggestions? Again, I apologize because I don't actually know how to do that, I was only making a friendly suggestion.
    – user377628
    Sep 20, 2014 at 17:54
  • 2
    Maybe you can try this answer. Set up the notification method, and move the text view accordingly when the height of the keyboard changes. I don't know if this would work in iOS 8 though.
    – user377628
    Sep 20, 2014 at 17:57
  • 1

6 Answers 6

128

You may disable the keyboard suggestions / autocomplete / QuickType for a UITextView which can block the text on smaller screens like the 4S as shown in this example

with the following line:

myTextView.autocorrectionType = UITextAutocorrectionTypeNo;

enter image description here enter image description here

And further if youd like to do this only on a specific screen such as targeting the 4S

if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
    if (screenHeight == 568) {
        // iphone 5 screen
    }
    else if (screenHeight < 568) {
       // smaller than iphone 5 screen thus 4s
    }
}
5
  • 2
    UITextAutocorrectionTypeNo is not working in iphone 6 - iOS 8.1
    – iGW
    Nov 10, 2014 at 11:51
  • 2
    @iGW when i did this after the UITextView or UITextField was already firstResponder it didn't work for me either. Try either setting it prior to that, or triggering resign and becomeFirstResponder (the former obviously being the "correct" and more appropriate way of doing this.
    – J_S
    Jun 8, 2015 at 15:11
  • How do I get the reference to the textView, given a UIWebView?
    – Maximus S
    Aug 31, 2015 at 17:34
  • 2
    FYI, for Swift the code is textField.autocorrectionType = .No
    – Rob Reuss
    Oct 25, 2015 at 20:31
  • For any subclass of Responder that implements UIKeyInput, the getter method for this variable can be implemented to return UITextAutocorrectionTypeNo to achieve the same effect when not using a UITextField.
    – bshirley
    Sep 20, 2016 at 16:53
53

For completeness sake I would like to add that you can also do this in the Interface Builder.

To disable Keyboard Suggestions on UITextField or UITextView — in the Attributes Inspector set Correction to No .

enter image description here

4
  • This did not work for me. The QuickType suggestion still displayed for my keyboard when I did this. But the programmatic answer did work for me.
    – Mike S
    Dec 10, 2014 at 17:57
  • It's weird that this didn't work for you because essentially what it does is set autocorrectionType to UITextAutocorrectionTypeNo. The same thing you do in code. Could you doublecheck, and if the behaviour doesn't change tell me what versions of Xcode and iOS are you using? Dec 10, 2014 at 19:41
  • 1
    I have this set to No on my project, and it still showed up on the Swype custom keyboard.
    – Almo
    Mar 25, 2015 at 22:13
  • I have not found a way to get that Swype keyboard to turn off that part. Incidentally, that thing is MASSIVE. I'll have to make my code query the size of it and adjust its animation for that.
    – Almo
    Mar 27, 2015 at 14:00
7

I've created a UITextView category class with the following method:

- (void)disableQuickTypeBar:(BOOL)disable
{
    self.autocorrectionType = disable ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;

    if (self.isFirstResponder) {
        [self resignFirstResponder];
        [self becomeFirstResponder];
    }
}

I wish there was a cleaner approach tho. Also, it assumes the auto-correction mode was Default, which may not be always true for every text view.

2

In Swift 2:

myUITextField.autocorrectionType = UITextAutocorrectionType.No
0
1

In Swift 4.x:

myUTTextField.autocorrectionType = .no
0

As others have said, you can use:

textView.autocorrectionType = .no

but I've also noticed people struggling with actually making the autocomplete bar swap out, since if the textView is already the firstResponder when you change its autocorrectionType, it won't update the keyboard. Instead of trying to resign and reassign the firstResponder status to the textView to effect the change, you can simply call:

textView.reloadInputViews()

and that should hide the autocomplete bar. See https://developer.apple.com/documentation/uikit/uiresponder/1621110-reloadinputviews

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.