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.