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