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

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;

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

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 7: Best way to implement an textview that presents previous input but is easy to clear

I'm porting a Mac app to the iPhone and I've run into an unexpected problem.
On the Mac there's a text field that is automatically pre-selected (= first responder) when a dialog shows up. The text field shows the text you entered in the field the last time and the text is pre-selected so that if you just start typing it gets cleared away. If you want to edit the existing text instead you just hit the forwards or backwards arrow.
On the iPhone this behavior seems very hard to implement. The text view shows up with the old text and I can even get it to pre-select but whatever I do the result is not quite right.
When I use
[aTextView setMarkedText: myText
selectedRange: newRange];
the text does show up as marked and if I just start typing the old text goes away. However there's no equivalent to the cursor keys on iOS, so I cannot NOT erase the text.. which is hardly the point.
What kind of iOS idiom would be appropriate for giving the option to either edit or overwrite existing text?
Best regards,
Frank
Try this code in your UITextViewDelegate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
dispatch_async(dispatch_get_main_queue(), ^{
[textView selectAll:self];
});
return YES;
}

Disable “…misspelled” message from VoiceOver on iOS

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?

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