Open up Apple's Calendar app. When you name a new appointment, it automatically capitalizes the first letter. It does not use the 'correction' style swap-out to do this.
For the life of me I can not reproduce this behavior. In IB I have set the UITextField's Capitalization to Word, but it seems to have no effect at all. If I turn on correction, it will swap-out the word with a capitalized version, but this isn't quite right.
Do I need to handle this in code, by checking each key press? This is probably trivial, except I'm worried about all of the corner cases I will miss, such as when the user manually uses 'shift' to negate the capitalization, or deletes and re-keys, in which case it shouldn't capitalize.
Or maybe there's a way to simply load the textfield with shift pressed? Is this the common way of implementing it?
Setting the capitalization to Word should do this, so something else is going wrong. Are you certain that's toggled on the actual UITextField that you're testing? Are you sure you're not maybe overriding it in code somehow? You can set it programmatically with:
[myTextField setAutocapitalizationType:UITextAutocapitalizationTypeWords];
There's also an exception (per the docs) where this will be ignored:
Some keyboard types do not support auto-capitalization. Specifically,
this option is ignored if the value in the keyboardType property is
set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or
UIKeyboardTypeNamePhonePad.
Does this apply to you?
Are you using the simulator or an actual device? If you are using the simulator, the casing will respect the shift and caps-lock state of the physical keyboard on your computer.
i just checked this in my app and it already did Capitalization by default. the behaviour is not determined by your application code, but by the global iphone settings.
start the iOS Settings. go to General, then Keyboard, there the user has the option for "Auto-Capitalization". is it off ?
in my case it was turned on, so my app and the calendar had this feature, when i turn it off, both apps are lacking this feature, because the user decided he does not want this feature.
Capitalization disable
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
To capitalize all characters
textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
To capitalize first character of sentence
textField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
To capitalization of first character of all words in sentense
textField.autocapitalizationType = UITextAutocapitalizationTypeWords;
Certain keyboards ignore the capitalization type
Some keyboard types do not support auto-capitalization. Specifically, this option is ignored if the value in the keyboardType property is set to UIKeyboardTypeNumberPad, UIKeyboardTypePhonePad, or UIKeyboardTypeNamePhonePad.
More details on the developer reference
Here is a Swift 2.0 update for all characters:
SomeTextField.autocapitalizationType = UITextAutocapitalizationType.AllCharacters
I had the same issue with capitalization property, i just changed keyboard type to Default and everything start working as expected. In my case i had previously set keyboardType to NamePhonePad that don't support auto-capitalization.
Related
Just noticed that in UITextView keyboard comes without change language button, unlike in UITextField. Why Apple removed this button from UITextView keyboard? Is there any way to enable this button? I want people to be able to write notes on any keyboard language added in phone settings.
EDITED: Maybe it will help somebody in the future. Just noticed that I set keyboard type to UIKeyboardTypeAlphabet and this option eliminates language button. Closing this question.
P.S. I have 3 languages enabled in test iPhone.
You are completely wrong. there is no difference in UIKeyboard in iOS whatsoever. It only depends on what keyboard types you use.
UIKeyboardTypeDefault and UIKeyboardTypeEmailAddress and UIKeyboardTypeTwitter all have those.
You set it like this:
txtField.keyboardType = UIKeyboardTypeTwitter;
UIKeyboardTypeDefault is obviously the default one for any UITextView or UITextField in iOS.
For anyone have this problem even when using UIKeyboardTypeDefault on a UITextView, go into the storyboard and make sure "Secure Text Entry" is unchecked. After unchecking this, the keyboard selector will return as well as the quick type keyboard.
How does one prevent “…misspelled” from being spoken by VoiceOver on a text field? Setting autocorrectionType to UITextAutocorrectionTypeNo doesn’t seem to make a difference.
If the iOS user types a misspelled word followed by a space or punctuation, Voiceover speaks the word followed by, “misspelled.” I want to be able to disable this behavior on a specific text field.
I would expect you to set spellCheckingType = UITextSpellCheckingTypeNo to get this behavior rather than autocorrectionType. Does that not resolve it?
I have the following code to make the first letter bold:
self.firstNameTexField_.autocapitalizationType = UITextAutocapitalizationTypeWords;
self.lastNameTextField_.autocapitalizationType = UITextAutocapitalizationTypeWords;
self.emailTextField_.autocapitalizationType = UITextAutocapitalizationTypeWords;
However, this doesn't make the first letter of the word capital. Any idea why?
Not mentioned here is that some keyboard types don't support the auto-cap feature, most notably:
NamePhonePad Specifies a keypad designed for entering a person’s
name or phone number. This keyboard type does not support
auto-capitalization.
Why a keyboard designed for a person's name doesn't support autocap is beyond me.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/swift/enum/c:#E#UIKeyboardType
Are you testing this in the simulator while typing on your computer's keyboard? When you do this the auto capitalization doesn't apply. If you tap on the keyboard in the app you should see the desired effect.
The problem for me was I was calling textField.becomeFirstResponder() before setting the autocapitalizationType. Once I switched the order so that textField.becomeFirstResponder() came after setting autocapitalizationType, it worked as expected.
self.firstNameTexField_.autocapitalizationType = UITextAutocapitalizationTypeWords;
Change
self.firstNameTexField_.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
Basically I am new to iOS development. I have several text boxes where I want a user to enter a percentage (not letters) so I will only need a numeric keyboard. When the user has done this I also want them to easily get rid of the keyboard.
In the simplest way possible, just treat me like a drunken 5-year-old here, can someone guide me through the steps needed to do this?
Assuming an UITextField:
textField.keyboardType = UIKeyboardTypeNumberPad;
I have a requirement wherein I have to change the text of the return key of the iPad to Sign-in. Obviously it is not one of the options available in the sdk. I have searched it over the net and it seems doing that possible.
The only question remaining is whether the app would be accepted by Apple if I modify the default system keyboard? The HIG is not clear on this , it states that "A custom input view can replace the system-provided onscreen keyboard in apps" and "You can also provide a custom input accessory view, which is a separate view that appears above the keyboard (or your custom input view)". Nothing about whether we are allowed to add an extra button on a system keyboard.
Any experiences??
#Vin you can change the name of return key of the keyboard to your requirement. I have an app that has the changed to return key name to Done and Search. And apple did not reject it.
To "Sign-In" you can use the return key UIReturnKeyJoin
textField.returnKeyType = UIReturnKeyJoin;
EDIT
Nope. You get the return key and
keyboard types defined in the OS.
Unless you want to try to hack the
keyboard's view hierarchy to change
that button, which would be a really
bad plan. (Standard recommendation
here is to file a bug report with
Apple to let them know you'd like
more/different options.)
see Custom iPhone return key text
Since I didn't get any satisfactory answer, I convinced the client that it would be inappropriate to modify the default system keyboard for a sake of one button(even if it is allowed by Apple). We are now going for the "Go" option available for return key.