user1437241
user1437241

Reputation: 55

Keyboard Type For UITextView

I would like to know how to obtain the keyboard type of a uitextview. I was able to obtain the keyboard type for a uitextfield by using textfield.keyboardtype but it doesnt seem to work for a uitextview. Kindly help me through this.

Thanks in advance.

Upvotes: 5

Views: 9036

Answers (4)

Meenakshi
Meenakshi

Reputation: 1162

You can obtain the keyboardType for a UITextView in the same way as you have done for UITextField.

 UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,320,30)];
 [self.view addSubview:textView];
 UIKeyboardType type = textView.keyboardType;
 [textView release];

Upvotes: 1

XIII
XIII

Reputation: 2044

This question would help you: UITextView does not seem to implement reloadInputViews

Upvotes: 0

David Hoerl
David Hoerl

Reputation: 41622

If you just read the UITextView class reference, it has a whole section on the Keyboard, and within that is this text:

"The appearance of the keyboard itself can be customized using the properties provided by the UITextInputTraits protocol. Text view objects implement this protocol and support the properties it defines. You can use these properties to specify the type of keyboard (ASCII, Numbers, URL, Email, and others) to display. You can also configure the basic text entry behavior of the keyboard, such as whether it supports automatic capitalization and correction of the text."

So this means that the UITextView adopts the UITextInputTraits protocol, meaning it responds to each of the required messages. To override methods, you would need to subclass UITextView, and then add methods to your subclass to return a different keyboard type etc.

For properties, you can just set the property as the other responder suggested.

Upvotes: 0

iOS Test
iOS Test

Reputation: 1103

try this

UITextView *txvw = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 24, 20)];
txvw.keyboardType =UIKeyboardTypeURL;

and alternate keyboard types are

UIKeyboardTypeDefault,                // Default type for the current input method.
UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

Upvotes: 9

Related Questions