Summary of common attributes of Uitextfield components in IOS app development _ios

Source: Internet
Author: User

Key attributes

After you use the IB in Xcode to drag a text box to the view, select the text box to set its various properties in the attribute Inspector.

Attribute Inspector is divided into three parts, namely Text Field, Control and View section. We'll focus on the Text Field section.

The Text Field section has the following options:

1. Text: Sets the default text for the text box.

2, Placeholder: You can display in the text box gray words, used to prompt the user should be in this text box to enter what content. When you enter data in this text box, the gray word used for the hint will automatically disappear.

3, Background:

4, Disabled: If selected, users will not be able to change the text box content.

5, followed by three buttons, to set the alignment.

6, Border style: Select the border style.

7, Clear button: This is a drop-down menu, you can choose to clear when the button appears, the so-called purge button is out of a text box right now small X, you can have the following options:

7.1 Never appears: never appear
7.2 appears while editing: appearing when editing
7.3 appears unless editing:
7.4 is always visible: always visible

8. Clear when editing begins: If selected, the previous contents of the text box will be cleared when you begin editing this text box. For example, you now enter "What" in the text box A, then edit the text box B, and if you come back and edit the text box A, then the "What" will be cleared immediately.

9. Text color: Sets the color of the text in the text box.

10, Font: Set the text font and font size.

11. Min Font Size: Sets the smallest font that the text box can display (but I don't feel it's going to work)

12. Adjust to fit: Specifies whether the text in the text box will shrink when the text box size is reduced. Select it to make all text visible, even if the text is very long. However, this option should be used in conjunction with the Min font size, and the text will not be smaller than the set min font size.

The next section is used to set how the keyboard is displayed.

13, Captitalization: Set uppercase. There are four options in the Drop-down menu:

13.1 None: Do not set uppercase
13.2 Words: Capitalize the first letter of each word, where the word refers to a string separated by a space
13.3 sentances: Capitalize the first letter of each sentence, where the sentence is a string separated by a period plus a space
13.4 All Characters: So the letter capital

14, Correction: Check spelling, the default is yes.

15, Keyboard: Select the keyboard type, such as full number, letters and numbers.

16, Appearance:

17, Return key: Select Back key, you can choose Search, returns, done and so on.

18, Auto-enable Return key: If you select this item, then only after the text box entered a character, the keyboard returned key is valid.

19, Secure: When your text box as a password input box, you can choose this option, at this point, the character is displayed as an asterisk.

Skills

Here are two tips:
One, Uitextfield hidden keyboard

1. Click the return of the keyboard to hide the keyboard

This method requires the implementation of the Uitextfielddelegate protocol in the corresponding. h file file. and add the following method to the. m file

Copy Code code as follows:

-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
[TextField Resignfirstresponder];
return YES;
}

2. Click on the blank space to hide the keyboard

The implementation of this method is mainly to the current view to increase the Click event, did not click the event to increase the corresponding processing method, here is to hide the keyboard, so we can click on the event corresponding method let Uitextfield give up the first responder.

Copy Code code as follows:

-(void) Dismisskeyboard
{
Nsarray *subviews = [Self.view subviews];
For (ID inputtext in subviews) {
if ([Inputtext Iskindofclass:[uitextfield class]]) {
if ([Inputtext Isfirstresponder]) {
[Inputtext Resignfirstresponder];
}
}
}
}

Add Click events for current View
Copy Code code as follows:

UITapGestureRecognizer *dismisskeyboardtap = [[UITapGestureRecognizer alloc] Initwithtarget:self Action: @selector (Dismisskeyboard)];
[Self.view Addgesturerecognizer:dismisskeyboardtap];

Second, to increase the content of the verification

Copy Code code as follows:

-(BOOL) textfieldshouldendediting: (Uitextfield *) TextField
{
Switch (Textfield.tag) {
Case 100://name
{
NSLog (@ "This is NameField");
Code to add validation name
Break
}
Case 101://phone
{
NSLog (@ "This is Phonefield");
Add code to verify phone
Break
}
Case 102://email
{
NSLog (@ "This is Emailfield");
Add code to verify email
Break
}
Default
Break
}
return YES;
}

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.