How to hide suggested email id from keyboard in swift - ios

I want to hide email suggestion which is displaying while i choose email textField in my application.
I have tried different options like below but none of them works for me.
txtEmail.autocorrectionType = .no
txtEmail.accessibilityLabel = .none
txtEmail.textContentType = .none
Is there anything else a part from this which i missed out ?

You can set UITextField text content type to an empty string:
txtEmail.textContentType = .init(rawValue: "")

I don't know how, but #Leo Dabus answer doesn't work in my case, however, an approach below does
textView.autocorrectionType = .no
textView.keyboardType = .emailAddress
I had to set keyboardType not to .default.

Related

how to change keyboard style programmatically in iOS?

I would like to change the keyboard style.
I have attached two pictures one the current situation and the second one is the desired situation.
try this to change the keyboard type:
self.someTextField.keyboardType = UIKeyboardType.decimalPad
and for number with special character try this :-
UIKeyboardType.numbersAndPunctuation
from :- https://developer.apple.com/documentation/uikit/uitextinputtraits#//apple_ref/c/tdef/UIKeyboardType
well thanks for suggetions and answers .
i found the solution for it.
for the numbers
textField.keyboardType = UIKeyboardType.numbersAndPunctuation
for the alphabets
textField.keyboardType = UIKeyboardType.emailAddress
- Keyboard Type Suggestions
textField.keyboardType = .emailAddress
After = . (Multiple Suggestions for keyboard type you can select according to your usage)

Setting UITextContentType.emailAddress on a UITextView is not working

I have a UITextView which is set with UIKeyboardType of .emailAddress
I want to auto-suggest the user's email address with the UITextContentType property
I do so like so:
if #available(iOS 10.0, *) {
myTextView.textContentType = UITextContentType.emailAddress
}
However this is not working and I see no email in the suggestion box of the textview.
I have also tried the same thing with a UITextField but no dice.
Is there something I am missing? I have done everything according to the docs.
Make sure you have set your email address in your own Contact card in the Contacts app.
:)
In case of email addresses you need to set your keyboardType to emailAddress also.
I thought prediction/autocomplete is broken on iOS 13 but you just need to specify the right type of keyboard. This is how I got names and addresses to work:
textField.autocorrectionType = .yes
textField.textContentType = .givenName
textField.keyboardType = .namePhonePad

UITextView autocapitalization is not working when keyboard is active

Currently, I am setting autocapitalization in a button target like this
//This method is fired when keyboard is still active
- (IBAction)changeAutoCapitalization:(id)sender
{
self.textView.autocapitalizationType = UITextAutocapitalizationTypeWords;
}
But this won't make keyboard to capital.
You have to call [self.textView reloadInputViews] after modifying the UITextAutocapitalizationType in order to change keyboard immediately.
If you find that you're doing a lot of text-related customizations, it might be helpful to subclass UITextView, to keep the functionality encapsulated.
Note: If testing on the simulator, make sure you are using the
Simulator's keyboard, by going to the menu: I/O -> Keyboard -> Toggle
Software Keyboard
If you are adding text automatically, for instance in response to a button tap, and the shift key turns off, then you can use this pattern:
autocapitalizationType = .allCharacters //Activate shift key
autocorrectionType = .no //Don't show all-caps auto suggest
reloadInputViews() //Apply changes
Then, to restore to sentences capitalization, for instance when a line is cleared:
if (autocapitalizationType = .allcharacters) {
autocapitalizationType = .sentences //Activate sentence capitalization
autocorrectionType = .yes //Show auto suggest
reloadInputViews() //Apply changes
}
Other capitalization options:
.none
.words
You may also need to do this when any non-enter key is pressed. To do so, override insertText from UIKeyInput, and check the entered text string:
if (text != "\n") {
if (autocapitalizationType == .allCharacters) {
autocapitalizationType = .sentences //Activate sentence capitalization
autocorrectionType = .yes //Show auto suggest
reloadInputViews() //Apply changes
}
//Respond to any character sequences
//...
}
Try to add this after initialization:
self.textView.autocapitalizationType = UITextAutocapitalizationTypeWords;
OR
It's very likely that the "Auto-Capitalization" option is turned off on that device. You can find that option in Settings > General > Keyboard.

How to dismiss suggestions at top of keyboard? [duplicate]

Is there any way to hide suggestions list above keyboard? I couldn't find any solution in documentation.
Yes there is. You have to disable autocorrection on the text field/text/any other class that conforms to the UITextInputTraits protocol, which can be done through the autocorrectionType property.
textField.autocorrectionType = .no
Additionally, if you're interested, the following are the only UIKeyboardTypes
that don't have suggestions by default.
DecimalPad
NumberPad
PhonePad
Swift 4.0 +:
textfield.autocorrectionType = .no
To hide the bar (predictive bar), use this code:
if #available(iOS 9.0, *) {
var item = textField.inputAssistantItem
item.leadingBarButtonGroups = [];
item.trailingBarButtonGroups = [];
}
For disabling copy-and-paste, use this function:
override func selectionRects(for range: UITextRange) -> [Any] {
return []
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
let menu = UIMenuController.shared
menu.isMenuVisible = false
return false
}
iOS 15 (maybe ealier)
The answers above did not work:
To remove the Suggestion list (predictive - spell checking)
Need to make:
textField.spellCheckingType = .no
That's what worked for me!
(Edited in June 2020: still true for Xcode 11.3.1)
In more recent versions of Xcode storyboards, you can also set the keyboard traits in the storyboard (right panel, the attributes inspector, then look for Text Input Traits and select the traits you want, at least in Xcode 9). In particular, select "No" for the Correction trait, as shown in the example below. Interestingly, this is for content type Username, and the Default selection for the Correction trait was to turn on Correction, unlike a content type like Password, for example.
As of August 19th, 2022 the following worked for me:
textField.spellCheckingType = .no
textField.autocorrectionType = .no
The other approaches did not work

iOS 8 - How to hide suggestion list above keyboard?

Is there any way to hide suggestions list above keyboard? I couldn't find any solution in documentation.
Yes there is. You have to disable autocorrection on the text field/text/any other class that conforms to the UITextInputTraits protocol, which can be done through the autocorrectionType property.
textField.autocorrectionType = .no
Additionally, if you're interested, the following are the only UIKeyboardTypes
that don't have suggestions by default.
DecimalPad
NumberPad
PhonePad
Swift 4.0 +:
textfield.autocorrectionType = .no
To hide the bar (predictive bar), use this code:
if #available(iOS 9.0, *) {
var item = textField.inputAssistantItem
item.leadingBarButtonGroups = [];
item.trailingBarButtonGroups = [];
}
For disabling copy-and-paste, use this function:
override func selectionRects(for range: UITextRange) -> [Any] {
return []
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
let menu = UIMenuController.shared
menu.isMenuVisible = false
return false
}
iOS 15 (maybe ealier)
The answers above did not work:
To remove the Suggestion list (predictive - spell checking)
Need to make:
textField.spellCheckingType = .no
That's what worked for me!
(Edited in June 2020: still true for Xcode 11.3.1)
In more recent versions of Xcode storyboards, you can also set the keyboard traits in the storyboard (right panel, the attributes inspector, then look for Text Input Traits and select the traits you want, at least in Xcode 9). In particular, select "No" for the Correction trait, as shown in the example below. Interestingly, this is for content type Username, and the Default selection for the Correction trait was to turn on Correction, unlike a content type like Password, for example.
As of August 19th, 2022 the following worked for me:
textField.spellCheckingType = .no
textField.autocorrectionType = .no
The other approaches did not work

Resources