IOS Uitextfield usage and method interpretation

Source: Internet
Author: User

Uitextfield is an important control in the user interaction in iOS development, and is often used to make account password boxes, input information boxes, and so on.

Initialize a text box:

Uitextfield * TextField = [[Uitextfield alloc]initwithframe:cgrectmake (100, 30, 100, 100)];

Set and get text box text:

@property (nonatomic,copy) NSString *text;

Create and get text from attributedstring:

@property (nonatomic,copy) nsattributedstring *attributedtext;

To set the font color properties:

@property (Nonatomic,retain) Uicolor *textcolor;

To set font properties:

@property (Nonatomic,retain) Uifont *font;

To set the font alignment format:

@property (nonatomic) nstextalignment textalignment;

To set the input box style:

@property (nonatomic) Uitextborderstyle BorderStyle;

This style is an enumeration, as follows:

typedef ns_enum (Nsinteger, Uitextborderstyle) {//without any border uitextborderstylenone,//Linear border Uitextborderstyleline, Shadow effect Border Uitextborderstylebezel,//Prototype effect border Uitextborderstyleroundedrect};

Set Default font properties

@property (nonatomic,copy) nsdictionary *defaulttextattributes;

The setting of this property affects the properties of all fonts.

Sets the grayscale string that is displayed by default

@property (nonatomic,copy) NSString *placeholder;

Setting the default string by attributedstring

@property (nonatomic,copy) nsattributedstring *attributedplaceholder;

Sets whether to empty the contents of the input box when you start editing

@property (nonatomic) BOOL clearsonbeginediting;

Sets whether the font size is adaptive with width (default is NO)

@property (nonatomic) BOOL adjustsfontsizetofitwidth;

Set minimum font size

@property (nonatomic) cgfloat minimumfontsize;

Set the background picture (will be stretched)

@property (Nonatomic,retain) UIImage *background;

Set the background picture when disabled

@property (Nonatomic,retain) UIImage *disabledbackground;

Whether you are editing (read-only property)

@property (nonatomic,readonly,getter=isediting) BOOL editing;

Whether to allow changing the character property dictionary

@property (nonatomic) BOOL allowseditingtextattributes;

Set Property Dictionary

@property (nonatomic,copy) nsdictionary *typingattributes;

Set the display mode of the Purge button

@property (nonatomic) Uitextfieldviewmode Clearbuttonmode;

This is an enumeration, as follows:

typedef ns_enum (Nsinteger, Uitextfieldviewmode) {//Never show uitextfieldviewmodenever,//show UITEXTFIELDVIEWMO when editing Dewhileediting,//non-editable time display uitextfieldviewmodeunlessediting,//At any time display uitextfieldviewmodealways};

Set the view to the left of the input box

@property (Nonatomic,retain) UIView *leftview;

Set the display mode for the left view of the input box

@property (nonatomic) Uitextfieldviewmode Leftviewmode;

Set the view to the right of the input box

@property (Nonatomic,retain) UIView *rightview;

Set the display mode for the right view of the input box

@property (nonatomic) Uitextfieldviewmode Rightviewmode;

Set the input box to be the first response when the View and secondary view (like keyboard) pop up

@property (ReadWrite, retain) UIView *inputview;
@property (ReadWrite, retain) UIView *inputaccessoryview;

This property sets whether to allow content to be inserted in the middle of the content when re-editing

@property (nonatomic) BOOL clearsoninsertion;

Logoff First Response (anticipation keyboard)

-(BOOL) Endediting: (bool) force;

Methods in the Uitextfielddelegate agent

Click on the input box to trigger the method, return Yes to enter the editing state, no is not.

-(BOOL) textfieldshouldbeginediting: (Uitextfield *) TextField;

method to invoke when editing is started
-(void) textfielddidbeginediting: (Uitextfield *) TextField;

method to invoke when editing is about to end , return Yes to end the edit state, no is not

-(BOOL) textfieldshouldendediting: (Uitextfield *) TextField;

to end an edit call method
-(void) textfielddidendediting: (Uitextfield *) TextField;

methods to invoke when entering characters
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string;

Click the function that is called when the button is cleared, return yes to clear, click No to clear

-(BOOL) Textfieldshouldclear: (Uitextfield *) TextField;

Click the return button to trigger the function
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField;



IOS Uitextfield usage and method interpretation

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.