IOS development-UI (5) UITextField,-uiuitextfield
Use UITextField
1. Creation Method
Example:
UITextField * text = [[UITextField alloc] initWithFrame: CGRectMake (20, 20,130, 30)];
2. Common methods and attributes
1) Border Style
@ Property (nonatomic) UITextBorderStyle borderStyle;
UITextBorderStyleNone has no border and the background is transparent by default.
UITextBorderStyleLine. The background is transparent by default.
UITextBorderStyleBezel bezel border. The background is transparent by default.
UITextBorderStyleRoundedRect rounded border. The background is white by default.
TextField. borderStyle = UITextBorderStyleBezel;
2) Prompt text: placeholder
TextField. placeholder = @ "enter the bank card password ";
3) keyboard type: keyboardType
TextField. keyboardType = UIKeyboardTypeNumberPad;
4) keyboard style: keyboardAppearance
TextField. keyboardAppearance = UIKeyboardAppearanceLight;
5) ciphertext input: secureTextEntry
TextField. secureTextEntry = YES;
6) re-edit whether to clear: clearsOnBeginEditing
TextField. clearsOnBeginEditing = YES;
7) horizontal text alignment: textAlignment
TextField. textAlignment = NSTextAlignmentRight;
8) text scrolling: adjustsFontSizeToFitWidth
Used with minimumFontSize
// Reclaim the keyboard
[Self. view endEditing: YES];
9) return key type: returnKeyType
@ Property (nonatomic) UIReturnKeyType returnKeyType;
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
10) Clear button mode: clearButtonMode
@ Property (nonatomic) UITextFieldViewMode clearButtonMode;
UITextFieldViewModeNever,
UITextFieldViewModeWhileEditing,
UITextFieldViewModeUnlessEditing,
UITextFieldViewModeAlways
3. UITextFieldDelegate Protocol
1) Can I enter the editing mode?
-(BOOL) textFieldShouldBeginEditing :( UITextField *) textField;
// NO is returned and cannot enter the editing status
Return YES;
2) the text box has entered the editing mode.
-(Void) textFieldDidBeginEditing :( UITextField *) textField;
3) Can the text box end the editing mode?
-(BOOL) textFieldShowEndEditing :( UITextField *) textField;
// NO is returned and the editing status cannot be ended.
Return YES;
4) The editing mode of the text box has ended.
-(Void) textFieldDidEndEditing :( UITextField *) textField;
5) Can I click the clear button?
-(BOOL) textFieldShouldClear :( UITextField *) textField;
// NO is returned. NO response is returned when you click the clear button.
Return YES;
6) Can I click the return button?
-(BOOL) textFieldShouldReturn :( UITextField *) textField;
// Remove the first responder
[TextField resignFirstResponder];
Return YES;
7) allow content modification
-(BOOL) textField :( UITextField *) textField shouldChangeCharactersInRange :( nsange) range replacementString :( NSString *) string; for example: if (textField. text. length >=6) {if ([string isEqualToString: @ ""]) {return YES;} return NO;} return YES ;}