IOS development-UI (5) UITextField,-uiuitextfield

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.