Uitextfield Manual Writing

Source: Internet
Author: User
Tags manual writing

One, Uitextfield manually write controls

Uitextfield *txtaccount = [[uitextfield alloc] initwithframe:cgrectmake (ten, ten,+) ];

// set up delegates

[Txtaccount setdelegate:Self];

// Set placeholder

[Txtaccount setplaceholder:@ " account "];

// set color

[Txtaccount setvalue:[uicolor Redcolor] forkeypath:@ "_placeholderlabel.textcolor"];

//  Set Font

[Txtaccount setvalue:[uifont boldsystemfontofsize:16] forkeypath:@ "_placeholderlabel.font"];

// Set text alignment

[Txtaccount settextalignment:nstextalignmentleft];

// set style

[Txtaccount setborderstyle:uitextborderstyleroundedrect];

// join the view

[Self. View addsubview: Txtaccount];

[Txtaccount release];

Second,uitextfielddelegate entrusted

// Set input box, whether can be modified

//no- cannot be modified, keyboard not present

//yes- can be modified, default value

-(BOOL) textfieldshouldbeginediting: (uitextfield *) textfield{

return YES;

}

The method is executed when you click the back key of the keyboard (lower-right corner).

// commonly used to hide the keyboard

-(BOOL) Textfieldshouldreturn: (uitextfield *) textfield{

if (txtaccount = = TextField) {

[txtaccount resignfirstresponder];

}

return YES;

}


The method is executed when the input box gets the focus.  

-(void) textfielddidbeginediting: (uitextfield *) textfield{

NSLog(@ "textfielddidbeginediting");


}


// Specify whether to allow text fields to end edit, allow text fields to lose first responder

-(BOOL) textfieldshouldendediting: (uitextfield *) textfield{

return YES;

}


// text box when you lose first responder, execute  

-(void) textfielddidendediting: (uitextfield *) textfield{

NSLog(@ "textfielddidendediting");

}

// indicates whether to allow content to be purged based on user requests

-(BOOL) textfieldshouldclear: (uitextfield *) textfield{

NSLog(@ "textfielddidendediting");

return YES;

}

// text box text, whether it can be modified

-(BOOL) TextField: (uitextfield *) TextField shouldchangecharactersinrange: (nsrange) Range replacementstring: (nsstring *) string{

return YES;

}

Uitextfield Manual Writing

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.