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.

rihekopo
  • 3,241
  • 4
  • 34
  • 63
  • 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. –  Sep 20 '14 at 17:18
  • 1
    @Hassan My problem is, that it destroys my UI, so I wanna hide/disable any suggestions. – rihekopo Sep 20 '14 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. –  Sep 20 '14 at 17:54
  • 2
    Maybe you can try [this answer](http://stackoverflow.com/a/5324303/377628). 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. –  Sep 20 '14 at 17:57
  • @Hassan , thank you. I think it would be good. My solution is something like the iMessage, and it does what you said. – rihekopo Sep 20 '14 at 19:26
  • 1
    possible duplicate of [ios8 xcode how to remove QuickType on UIKeyboard ( auto complete / auto suggest )](http://stackoverflow.com/questions/24031362/ios8-xcode-how-to-remove-quicktype-on-uikeyboard-auto-complete-auto-suggest) – brigadir Sep 22 '14 at 13:47
  • Terrible. Why would people want to use your app for chat, when you disable autocomplete and autocorrect? Fix your app to work correctly. – Léo Natan Sep 22 '14 at 20:51
  • Some kind of built-in keyboard (e.g. Japanese) has Quicktype like completion view from iOS5. http://www.macstories.net/news/hack-brings-auto-correct-bar-to-default-ios-5-keyboard/. You should not predicate the size of keyboard anyway. – rintaro Sep 23 '14 at 05:48
  • @Hassan, in my case i cant move the text view since there is no room on the 4S small screen to fit all the views. I had to disable it. – mihai Oct 22 '14 at 06:02

6 Answers6

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
    }
}
mihai
  • 4,184
  • 3
  • 26
  • 27
  • 2
    UITextAutocorrectionTypeNo is not working in iphone 6 - iOS 8.1 – iGW Nov 10 '14 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 08 '15 at 15:11
  • How do I get the reference to the textView, given a UIWebView? – Maximus S Aug 31 '15 at 17:34
  • 2
    FYI, for Swift the code is textField.autocorrectionType = .No – Rob Reuss Oct 25 '15 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 '16 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

Nikita Kukushkin
  • 14,648
  • 4
  • 37
  • 45
  • 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 '14 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? – Nikita Kukushkin Dec 10 '14 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 '15 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 '15 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.

DZenBot
  • 4,806
  • 2
  • 25
  • 27
2

In Swift 2:

myUITextField.autocorrectionType = UITextAutocorrectionType.No
Nagendra Rao
  • 7,016
  • 5
  • 54
  • 92
1

In Swift 4.x:

myUTTextField.autocorrectionType = .no
yo2bh
  • 1,356
  • 1
  • 14
  • 26
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

Rance
  • 1