4. iOS programming UITextFiled
The buttons mentioned above, let's take a look at how UITextField is used.
Code: AppdDelegate. m
// Define the variable UITextField * textField;-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {self. window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen] bounds]; self. window. backgroundColor = [UIColor whiteColor]; UIViewController * viewController = [UIViewController alloc]; self. window. rootViewController = viewController; UIView * rootView = [[UIView alloc] initWithFrame: [UIScreen mainScreen] bounds]; viewController. view = rootView; /******************** UITextField ****************** ** // create UITextField textField = [[UITextField alloc] init]; // set the UITextField position, width and height textField. frame = CGRectMake (100,100,200, 30);/*** set the border style with the following enumerated values: * UITextBorderStyleNone (unformatted) * UITextBorderStyleLine (line) * UITextBorderStyleBezel (3D) * UITextBorderStyleRoundedRect (rounded corner) */textField. borderStyle = UITextBorderStyleRoundedRect; // set the background color textField. backgroundColor = [UIColor yellowColor]; // sets the default input text. // textField. text = @ "text"; // sets the prompt text textField. placeholder = @ "Jss"; // The original content textField is automatically cleared when you edit it again. clearsOnBeginEditing = YES; // minimum text value // textField. minimumFontSize = 10.0f; // The text is automatically reduced as the text box decreases. adjustsFontSizeToFitWidth = YES;/*** automatically convert the size of the input text in the text box * UITextAutocapitalizationTypeNone (not switched) * UITextAutocapitalizationTypeWords (the first letter of each word) * begin) * UITextAutocapitalizationTypeAllCharacters (all letters) */textField. autocapitalizationType = UITextAutocapitalizationTypeWords;/*** set the keyboard type ** UIKeyboardTypeDefault (default keyboard) * UIKeyboardTypeASCIICapable (English letter keyboard) * numeric and punctuation keyboard) * UIKeyboardTypeURL (URL keyboard) * UIKeyboardTypeNumberPad (numeric keypad) * UIKeyboardTypePhonePad (Dialing keypad) * keyboard (personalized dialing keypad) * UIKeyboardTypeEmailAddress (enter the keyboard of the e-mail address) * UIKeyboardTypeDecimalPad (Keypad with numbers and decimal points) * UIKeyboardTypeTwitter (Twitter keyboard) * UIKeyboardTypeWebSearch (Webpage Search keyboard) */textField. keyboardType = UIKeyboardTypeNamePhonePad;/*** set the Clear button type ** UITextFieldViewModeNever (the Clear button is never displayed) * UITextFieldViewModeWhileEditing (the Clear button is displayed when editing) * UITextFieldViewModeUnlessEditing (the Clear button is displayed except for editing) * UITextFieldViewModeAlways (the Clear button always appears) */textField. clearButtonMode = UITextFieldViewModeWhileEditing; // Add UITextField to view [rootView addSubview: textField]; [self. window makeKeyAndVisible]; return YES;}/*** release keyboard */-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {[textField resignFirstResponder];}Running result:
It is worth noting that the last touchesBegan: method. If you do not have this piece of code, the keyboard will not be automatically removed after you have entered it in the input box. Therefore, we need to get the current response and then turn off the keyboard. It is especially important to remember.
In the basic section, let's briefly introduce the relevant content and then explain other usage methods.
Chapter 4. End!
The content in this article is original. For reposted content, please indicate the source. It cannot be used for commercial purposes. Thank you!