iOS UI Learning-uitextfield Agent

Source: Internet
Author: User
Tags uicontrol

</pre><pre name= "code" class= "OBJC" > #import "ViewController.h"//Signed Proxy agreement @interface Viewcontroller () <    Uitextfielddelegate> @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; Note: Uitextfield inherits from Uicontrol, and Uitextview inherits from Uiscrollview,uiscrollview and inherits from UIView//Create input box Uitextfield *textfield =    [[Uitextfield Alloc] Initwithframe:cgrectmake (20, 50, 280, 100)];    Sets the border style of the input box Textfield.borderstyle = Uitextborderstyleroundedrect;    Sets the current object as the input box for the proxy textfield.delegate = self;    The Delete button on the right textfield.clearbuttonmode = uitextfieldviewmodealways;    Add to Current View [Self.view Addsubview:textfield]; Because Uitextfield inherits from Uicontrol, you can do the following, which can be used to control the length of text in the input box and the input limit [TextField addtarget:self action: @selector (pick) Forcontrolevents:uicontroleventeditingchanged];} -(void) pick{NSLog (@ "text content changed");} #pragma mark-uitextfielddelegate//allow the input box to be edited-(BOOL) textfieldshouldbeginediting: (Uitextfield *) textfield{//return   Yes indicates that you can edit and return no indicates that you cannot return YES;} became first responder (becomes the primary responder, display keyboard)-(void) textfielddidbeginediting: (Uitextfield *) textfield{//Once the method for editing the response is changed}// Return yes to allow to stop editing and to close the keyboard, return no means stop editing-(BOOL) textfieldshouldendediting: (Uitextfield *) textfield{return YES;} -(void) textfielddidendediting: (Uitextfield *) textfield{//Once the method of editing the response is ended}//This method is called when the content changes, restricting the length of the text within the input box-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) Range replacementstring: (NSString *)     string{////Limit the length of text within the input box, the length of the text does not increase when the length is greater than or equal to 10, and cannot be deleted if (TextField.text.length >=) {return NO;    }else{return YES; }}//when the Delete button exists, use this method to control whether the button is valid, which can be deleted by default-(BOOL) Textfieldshouldclear: (Uitextfield *) textfield{return NO;} Click Return Response Event-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{//Logout First responder, close keyboard [TextField resignfirstrespon    Der]; return YES;} @end

< Span style= "" > development, uitextfield The use of frequency or relatively high, such as the general account login, etc. are used to uitextfield uitextfield

Welcome to join QQ Group Name: IOS Coterie Group number:177204933; progress and growth along the path of IOS development.



iOS UI Learning-uitextfield Agent

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.