To put it short, thank you for your attention. This article has been written for a long time. I will continue to learn about ios. I will use 2 to 3 articles to learn some common controls on the iphone, including Image View, Text Field, Keyboard, Slider, and so on. This article covers the use of ImageView and Keyboard. After completion, it is as follows:
1) create a new project, select "Single View Application", name it "Control Fun", and save it.
2) Add ImageView
3) upload an image to the project. The entire process is simple. Select an image and drag it to the Supporting Files folder in the project navigator.
4) add images to ImageView
5) resize the image
For processing the image size and display mode, the iphone recommends that you provide images of the appropriate size (that is, the size of the image is the same as the size of the image to be displayed on the iphone, the cpu of the iphone is not needed for more processing, which helps the program to run quickly and reduce cpu consumption). If the same image needs to be displayed in two sizes, then you can upload two images to the program.
6) Adjust the original size of the ImageView to the image.
7) add two labels and two textfields.
8) Rename the Label and adjust the textfield size.
9) add Placeholder text to textfield
Now, all the interface la S have been completed. Next, we will go to the code stage and learn how to call the iphone virtual keyboard.
10) virtual keypad
Now, a new problem occurs again. How can we hide the keyboard after the input is complete? When you click the "return" button On the virtual keyboard, it will call an Event called "Did End On Exit event". We can associate an Action with this event, when this event is triggered, call Action to hide the keyboard. The following describes how to hide the keyboard.
11) Create an Outlet
# Import <UIKit/UIKit. h> @ interface BIDViewController: UIViewController @ property (weak, nonatomic) IBOutlet UITextField * nameField; @ property (weak, nonatomic) IBOutlet UITextField * numberField; @ endBIDViewController. m
# Import "BIDViewController. h" @ implementation BIDViewController @ synthesize nameField; @ synthesize numberField ;......We added two outlets pointing to textfield, named nameField and numberField respectively.
12) manually add an Action
# Import <UIKit/UIKit. h> @ interface BIDViewController: UIViewController @ property (weak, nonatomic) IBOutlet UITextField * nameField; @ property (weak, nonatomic) IBOutlet UITextField * numberField;-(IBAction) Unique :( id) sender; @ endB) implement the textFieldDoneEditing method at the end of BIDViewController. m.
- (IBAction)textFieldDoneEditing:(id)sender{ [sender resignFirstResponder];}
(The following is my personal understanding of resignFirstResponder. If there are any mistakes, I hope you can correct them. Thank you !)
13) Associate Action
14) implementation principle
Select the Root View in Objects and change the UIView to UIControl in identity inspector.
15) create another Action: backgroundTap
-(IBAction) backgroundTap :( id) sender;
BIDViewController. m
- (IBAction)backgroundTap:(id)sender{ [nameField resignFirstResponder]; [numberField resignFirstResponder];}
16) Associate Action
Compile and run the program again, enter a number in the second textfield, and click anywhere on the screen. The virtual keyboard disappears.
So far, all functions have been developed.