IOS Development Series 3-UITextField usage Summary
// Initialize the input box and set the location and size of UITextField * textField = [[UITextField alloc] initWithFrame: CGRectMake (10,100,300, 30)]; // set the input box to prompt textField. placeholder = @ "TextField Tip"; // pre-input text textField in the input box. text = @ "pre-input text"; // set the text font textField in the input box. font = [UIFont fontWithName: @ "Arial" size: 20366f]; // set the font color of the input box textField. textColor = [UIColor redColor]; // sets the background color of the input box textField. backgroundColor = [UIColor grayColor]; // you can specify the border style textField in the input box. borderStyle = border; // There are several border styles: // enum {// UITextBorderStyleNone, no border, default // UITextBorderStyleLine, wired border // UITextBorderStyleBezel, wired border and shadow // UITextBorderStyleRoundedRect rounded border //} UITextBorderStyle; // set whether the input box is used for the password textField. secureTextEntry = NO; // you can specify when the Clear button is displayed to delete all textfields in the input box at a time. clearButtonMode = quiet; // There are several types of Clear button styles: // enum {// UITextFieldViewModeNever, which never appears // when editing. // UITextFieldViewModeUnlessEditing, in addition to editing, all appear // UITextFieldViewModeAlways always appear //} UITextFieldViewMode; // you can set the automatic correction mode textField. autocorrectionType = optional; // automatic error correction methods include: // enum {// UITextAutocorrectionTypeDefault, default // optional, no automatic error correction // UITextAutocorrectionTypeYes, automatic error correction //} UITextAutocorrectionType; // set the automatic capital mode textField. autocapitalizationType = UITextAutocapitalizationTypeNone; // There are several automatic capitalization methods: // enum {// UITextAutocapitalizationTypeNone, which is not automatically capitalized // UITextAutocapitalizationTypeWords, the first letter is capitalized/upper, upper-case letters of a sentence // UITextAutocapitalizationTypeAllCharacters; all letters are in upper-case. //} UITextAutocapitalizationType; // set whether to clear textField after editing again. clearsOnBeginEditing = YES; // sets textField for text alignment. textAlignment = NSTextAlignmentLeft; // There are several text Alignment Methods in iOS7: // enum {// NSTextAlignmentLeft = 0, left alignment, default // NSTextAlignmentCenter = 1, center Align // NSTextAlignmentRight = 2, right align // NSTextAlignmentJustified = 3, natural alignment on the last line of a paragraph // NSTextAlignmentNatural = 4, default aligment //} NSTextAlignment; // set whether the font size automatically adapts to the width of the input box. The default value is to keep the original size and scroll textField for long text. adjustsFontSizeToFitWidth = YES; // you can specify textField to automatically reduce the size of the smallest font displayed. minimumFontSize = 20; // set the keyboard style textField. keyboardType = UIKeyboardTypeNumberPad; // The keyboard style includes the following types: // enum {// UIKeyboardTypeDefault; default keyboard; supports all characters // UIKeyboardTypeASCIICapable; Supports the default ASCII keyboard // notepad, the standard phone keyboard supports + * # characters // UIKeyboardTypeURL. Only the URL keyboard with URL characters is supported. com button // UIKeyboardTypeNumberPad, digital keyboard // UIKeyboardTypePhonePad, telephone keyboard // enter the name of the phone keyboard // UIKeyboardTypeEmailAddress, email keyboard // UIKeyboardTypeDecimalPad, a numeric keyboard with numbers and decimal points // UIKeyboardTypeTwitter, an optimized keyboard that facilitates the input of @, # character // UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, //} UIKeyboardType; // sets the return key style textField. returnKeyType = UIReturnKeyDone; // The return key has the following styles: // enum {// UIReturnKeyDefault, default, gray, and marked with Return // UIReturnKeyGo, blue button marked with Go // UIReturnKeyGoogle, blue button marked with Google, used for search // UIReturnKeyJoin, blue button marked with Join // UIReturnKeyNext, blue button marked with Next // UIReturnKeyRoute, blue button marked with Route // UIReturnKeySearch, blue button marked with Search // UIReturnKeySend, blue button marked with Send // UIReturnKeyYahoo, blue button marked with Yahoo // UIReturnKeyYahoo, the blue button marked with Yahoo // UIReturnKeyEmergencyCall, emergency call button //} UIReturnKeyType; // sets the keyboard appearance textField. keyboardAppearance = UIKeyboardAppearanceDefault; // There are two types of keyboard exterior: // enum {// UIKeyboardAppearanceDefault; default exterior: light gray // dark gray, graphite //} UIReturnKeyType; // sets the proxy to implement the textField protocol. delegate = self; // Add the following code to the rightmost side: UIImageView * image = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "right.png"]; textField. rightView = image; textField. rightViewMode = UITextFieldViewModeAlways; // Add the input box to the view [self. view addSubview: textField]; // Press return to collapse the keyboard-(BOOL) textFieldShouldReturn :( UITextField *) textField {[text resignFirstResponder]; return YES ;}