how to change keyboard style programmatically in iOS? - 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)

Related

How to hide suggested email id from keyboard in swift

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.

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

Setting capitalization of the first letter on keyboard

I have a button which presents an alert with a text field in it. When clicked on the button it automatically focuses in the text field and keyboard shows. However the letters in the keyboard start as lower-case. How can I fix that so it starts as upper-case?
Edit:
alertTextField.autocapitalizationType = .sentences
This was what I was looking for.
Try this
let mytextfield = UITextField()
mytextfield.autocapitalizationType = .allCharacters
Other types :

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 can I completely remove the hide/done button from a keyboard in a swift app?

I have a following code:
textView.returnKeyType = UIReturnKeyType.Done
that makes my keyboard look like this:
but I would like to get rid of the done/return button and achieve this:
what's the best way of doing it in swift?
You cannot achieve this by changing the return button type, instead you need to change the keyboard type. In order to change the keyboard type to match the one you posted that you would like to match, use the twitter keyboard type.
Swift 2
textView.keyboardType = .Twitter
Swift 3
textView.keyboardType = .twitter

Resources