Tips for using the soft keyboard for iOS development

Source: Internet
Author: User

In the course of iOS development, it is sometimes necessary to eject a soft keyboard for input and sometimes to hide the soft keyboard in some cases to improve the user experience.

Today there are a few tips on soft keyboards to share with you.

(1) Just eject the numeric keypad

There are some requirements that require users to only enter numbers in the text field, what do they need to do? The ability to write a regular table to infer user input, or to perform character matching, and so on.

But it's all about writing code. The program apes are lazy-loving. In iOS, you can simply set the pop-up as a numeric keypad so that the user input is just a number.

Select a text Field. Select Show the Attributes inspector on the right side. Select the keyboard type in the keyboard type below. For example, you can choose number Pad.

This allows you to enter only the numbers.


Implementation effects such as the following:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">.


(2) Hide keyboard after clicking button

In the actual development requirements, the user may click on a button after the text has been lost. Indicates that the keyboard should be hidden when the input is complete. Instead of the keyboard is always displayed on the interface, affecting the user experience.

The detailed implementation only needs to remove the focus from the input box after the button is clicked.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">.

After implementing the above code, click on the button to hide the keyboard.


(3) Click on the screen to hide the keyboard regardless of location

In the course of our use. How do you often do this by scrolling through the interface, or by tapping the random area to hide the keyboard? This requires overriding method Touchesended (). Detailed implementations such as the following:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">.


There are a lot of tips on how to operate the keyboard, and I'll share it with you later.



GitHub home: https://github.com/chenyufeng1991. You are welcome to inquire.


Tips for using the soft keyboard for iOS development

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.