IPhone UI design registration page implementation and TextField disable the keyboard two methods

Source: Internet
Author: User

In Xcode4.3.2, create an IOS CocoaTouch project named register. Define four output ports in ViewController. h: user, pass, year, sex;

Because the Label does not need to obtain data, the output port is not defined. Two buttons are defined: Cancal and OK;

The ViewController. h is defined as follows:

[Plain]
//
// ViewController. h
// Register
//
// Created by bo Yangon 5/10/12.
// Copyright (c) 2012 _ MyCompanyName _. All rights reserved.
//
 
# Import <UIKit/UIKit. h>
 
@ Interface ViewController: UIViewController
 
{
UIButton * cancal;
UIButton * OK;
UITextField * textuser;
UITextField * textpass;
UITextField * textsex;
UITextField * year;
}
@ Property IBOutlet UIButton * cancal;
@ Property IBOutlet UIButton * OK;
@ Property IBOutlet UITextField * textuser;
@ Property IBOutlet UITextField * textpass;
@ Property IBOutlet UITextField * textsex;
@ Property IBAction UITextField * year;
@ End
Implement the memory function in the header file and the implementation file respectively:

[Plain]
//
// ViewController. m
// Register
//
// Created by bo Yangon 5/10/12.
// Copyright (c) 2012 _ MyCompanyName _. All rights reserved.
//
 
# Import "ViewController. h"
 
@ Interface ViewController ()
 
@ End
 
@ Implementation ViewController
@ Synthesize cancal;
@ Synthesize OK;
@ Synthesize textuser;
@ Synthesize textpass;
@ Synthesize textsex;
 
 
-(Void) viewDidLoad
{
[Super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
 
-(Void) viewDidUnload
{
[Super viewDidUnload];
// Release any retained subviews of the main view.
}
 
-(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation
{
Return (interfaceOrientation! = UIInterfaceOrientationPortraitUpsideDown );
}
 
@ End

Then we design the UI in the ViewController. xib file:

 

"Register" is the Label and the font size and color are modified;

Added a background;

Button: Cancal, OK

Then we can disable the keyboard:

First, add a method to the header file ViewController. h:

[Plain]
-(IBAction) TextFieldDoneEditing :( id) sender;
Implement this method in ViewController. m:

[Plain]
-(Void) TextFieldDoneEditing :( id) sender
{
[Sender resignFirstResponder];
}
Then, connect the Did End on Exit method of the four textfields to the TextFieldDoneEditing method to disable the keyboard function through the soft keyboard return.

Because the input information is different, the activated keyboard format is different. For example, the Number key does not have the return key. How can we disable this keyboard?

Add a new method in ViewController. h:

[Plain]
-(IBAction) BackgroundClick :( id) sender;

Implemented in ViewController. m:

[Plain]
-(Void) BackgroundClick :( id) sender
{
[Textuser resignFirstResponder];
[Textpass resignFirstResponder];
[Textsex resignFirstResponder];
[Textyear resignFirstResponder];
}

Add each textField and connect the touch up inside method of each TextField to the BackgroundClick method.

In this way, after entering the content, click the inactive background to close the keyboard. Let's try it. Please leave a message for me if you have any questions. Thank you.



From Anno's column

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.