autocapital words not working in UITextField - ios

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;

Related

How to implement iOS keyboard number pad?

I'm making a custom keyboard so at first wanna make the one similar with real iOS keyboard.
On the iOS keyboard when I tap [123] button, the alphabet keys changes to number keys. THIS is what I want to do.
Is there any special ways for this?
self.textField.keyboardType = UIKeyboardType.NumberPad

Autocapitalization of words does not work in UITextView

I've got a UITextView that needs to autocapitalize words. However, when I call any of these methods, the view does not respond.
[self.fullNameTextView setAutocapitalizationType:UITextAutocapitalizationTypeWords];
self.fullNameTextView.autocapitalizationType = UITextAutocapitalizationTypeWords;
Is this a bug in iOS 8.1?
I had the same issue and was able to solve it by settings my Keyboard type back to DEFAULT:
Please check your device Settings → General → Keyboard → Auto-Capitalization is turned on.
Both methods are valid of setting the property are valid. Are you testing using the simulator?
I found that autocapitalisation works only if you disable the hardware keyboard in Hardware > Keyboard > Connect Hardware Keyboard (Uncheck) and use the onscreen software keyboard. I tested this with iOS 8.1 with both UITextField and UITextView.
Edit
These properties determine the behaviour during manual input only. If you require the capitalisation of text that you are setting programmatically into the text view, use the following method:
NSString *myString = #"this is my uncapitalised string";
self.fullNameTextView.text = [myString capitalizedString]
self.fullNameTextView.autocapitalizationType = UITextAutocapitalizationTypeWords;
Note: It will not work if its simulator or Auto-Capitalisation is turned off from Settings>General>Keyboard>Auto-Capitalisation on iOS/iDevice. this solution doesn't work if auto correction is disabled for text view.

UITextView with voiceover

Here is my very simple code for creating a UITextView.
UITextView *textView = [[UITextView alloc] initWithFrame:self.view.bounds];
textView.editable = NO;
textView.text = #"Using iOS 3.0 and later, VoiceOver is available to help users with visual impairments use their iOS-based devices. The UI Accessibility programming interface, introduced in iOS 3.0, helps developers make their applications accessible to VoiceOver users. Briefly, VoiceOver describes an application’s user interface and helps users navigate through the application’s views and controls, using speech and sound. Users familiar with VoiceOver in Mac OS X can leverage their experience to help them quickly come up to speed using VoiceOver on their devices.";
[self.view addSubview:textView];
Given that I could not possibly do anything wrong here I am just wondering if this is an expected behaviour or a bug perhaps somebody also faced:
With voiceover enabled I expect the entire text view to be “highlighted” on tap, then its accessibilityLabel to be read to a user and after they double tap, the entire text view’s text to be read.
But what is happening is that a small portion of the text view is highlighted (usually 2 lines), accessibilityLabel is not read, but the first “highlighted" line and the first letter (!) of the second line are read instead and only after a user double taps the entire text is read.
Especially reading the first letter in the second highlighted line confuses me. Plus shouldn’t accessibilityLabel be always read in the beginning?
This looks like a big to me but Apple has always paid so much attention to accessibility, so I’m having doubts if I should report it, may be the meant it to be this way.
Another question: is there a way to achieve the following behaviour (without subleasing UITextView) when voiceover is enabled: user taps UITextView -> accessibilityLabel and the entire text are read?
In case someone else has this problem here is the answer:
textView.accessibilityTraits = UIAccessibilityTraitStaticText;
Combining the other two answers from this post has the desired effect. i.e.
textView.isAccessibilityElement = true
textView.accessibilityTraits = .staticText
Also if you are setting the attributedText property on the UITextView make sure you DO NOT set the accessibilityLabel (on the UITextView). Doing so will cause VoiceOver (Xcode 12.5, iOS 14.4.2) to read the text twice.
textView.isAccessibilityElement = true
This Works

iOS - My TextBox spawns a regular keyboard when clicked, how can I set it to spawn a numeric keyboard?

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;

Capitalization of UITextField

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.

Resources