In this recipe, we will learn how to set some of the different virtual keyboard styles.
In this recipe, we will discuss the usage of the UITextBox
object and how we can display editable text within it.
In order to see how this can be achieved, we need to modify the ViewObjectsExample application that we created in the previous recipe. Perform the following steps to do so:
ViewObjectsExample.xcodeproj
project file.ViewController.m
implementation file from the project navigator.populateTextBox
method, as shown in the highlighted lines of the following code snippet:-(void)populateTextBox { self.txtTextInput.text = @"This is some sample text"; self.txtTextInput.keyboardType = UIKeyboardTypeNumbersAndPunctuation; self.txtTextInput.returnKeyType = UIReturnKeyDone; self.txtTextInput.delegate = self; }
When the compilation completes, the iOS Simulator will appear and display the textbox with our populated sample text. Tap into the TextField
control to display our specified keyboard type.
In the following code snippet, we update the keyboardType
property of the TextField
control and then specify UIKeyboardTypeNumbersAndPunctuation
as the keyboard type to use.
-(void)populateTextBox { self.txtTextInput.text = @"This is some sample text"; self.txtTextInput.keyboardType = UIKeyboardTypeNumbersAndPunctuation; self.txtTextInput.returnKeyType = UIReturnKeyDone; self.txtTextInput.delegate = self; }
The keyboardType
property accepts an enumeration type named UIKeyboardType
. The following table explains some of these types:
If you would like to find out more information on the UIKeyboardType
class, you can refer to the Apple Developer documentation, located at http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITextInputTraits_Protocol/Reference/UITextInputTraits.html.