IOS development tips

Source: Internet
Author: User

IOS development tips

During iOS development, you sometimes need to bring up a soft keyboard for input, and sometimes you need to hide the soft keyboard in some cases to improve the user experience. Today I will share some tips on the soft keyboard.

(1) only the numeric keyboard is displayed.

In some cases, users are required to enter only numbers in Text Field. How can this problem be solved? You can write a regular expression to determine user input, or perform character matching. However, code is required. Programmers love to be lazy. In iOS, you can use the simple settings to enable the pop-up as a digital keyboard, so that the user input can only be a number.

Select a Text Field. Select Show the Attributes inspector on the right. Select the KeyBoard Type in the KeyBoard Type below. For example, you can select Number Pad. In this way, only numbers can be entered.

.

 

The implementation result is as follows:

.

 

(2) click the button to hide the keyboard

In actual development requirements, users may click a button after entering the text to indicate that the input is complete. In this case, the keyboard should be hidden. The keyboard is not always displayed on the interface, which affects the user experience. For specific implementation, you only need to remove the focus from the input box after clicking the button.

.

After the above Code is implemented, click the button to hide the keyboard.

 

(3) Click anywhere on the screen to hide the keyboard

During our use, we often scroll through the interface or click any area to hide the keyboard. What should we do at this time? In this case, you need to override touchesEnded (). The specific implementation is as follows:

.

 

There are still many tips on keyboard operations. I will share them with you later.

 

 

 

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.