Keyboard events for iOS Uitextfield

Source: Internet
Author: User

Instructions for use: Write your own Uitextfield control code

(1) Keyboard exit when you click the return key of the keyboard

The Uitextfield defined in the. h file is as follows:in the. m file-(void) Viewdidload write the following code:Textfild=[[uitextfield Alloc]initwithframe:cgrectmake (20, 200,200, 20)];
textfild.layer.borderwidth=2;
Textfild.layer.bordercolor=[[uicolor Blackcolor]cgcolor];
textfild.delegate=self;
[Self.view Addsubview:textfild];to add a keyboard to the. m file, the corresponding event is as follows:-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
[Self.textfild resignfirstresponder];//cancellation of the first corresponding person
return YES;
}The above operation can complete the keyboard corresponding events, just the first way. (2) The background of the first view when the keyboard exitsfirst, open the. xib file, manually change the class in the custom class to: Uicontrol, as shown insecond, the mouse is selected. Xib, after finding the event, drag the mouse to the current view of the file's owner to go to the operation as shownthird, the process of selecting the event name will appear after the last step, and selecting the appropriate event name is OK. Iv. Add the following statement to the already written event. The keyboard can exit when you click on the view background. -(Ibaction) Backgroud: (ID) sender{
[Self.textfild Resignfirstresponder];

Keyboard events for iOS Uitextfield

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.