"We all love Paul Hegarty." Stanford IOS8 public class personal note uitextfield text box

Source: Internet
Author: User

This session describes the component Uitextfield in the Uikit framework.


Uitextfield (text boxes) and labels look like, but text boxes can be edited. Use the text box in the UI to be aware, because the input text on the emulator can use the computer keyboard, and on the real machine, the user can only use the virtual keyboard, so be careful. You can also set the text size, color, and so on in the textbox, just as you would in a label.

Each time we click on the text box to start typing, the text box will be the first responder on the page, and the virtual keyboard will slide out of the bottom to match our input as if the text box in the Web development has been focused. You can use method Becomefirstresponder to specify that an object becomes the first responder of the current page. If you want to make the keyboard disappear, we just need to make the text box a first responder, using the method Rsignfirstresponder.

At the end of our input, click on the return key on the keyboard (of course, the text displayed by this key can be edited) will trigger the proxy method Textfieldshouldreturn, Usually you will write the Sender.resignfirstresponder in this method to close the virtual keyboard.


When the editor is finished and the TextField is called the first responder again, another proxy method textfielddidendediting will be invoked.

Uitextfield can also act as a controller for a UI, just like a button, we can trigger the target and action via a button, or we can trigger some action and target via a uitextfield. Only the events and buttons that are triggered are different. Here's a look at the keyboard:


The keyboard appears because the text box sends a message to the interface Uitextinputtraits protocol, which is followed by the Uitextfield class. You can use the properties in the protocol to set up, such as the name of the return button display, ciphertext input, and so on, which can also be set in the property inspector.


When the keyboard slides out may obscure other views on the page, we need to adapt these views to the location of the keyboard (especially the text box itself) and use the nsnotification associated with the keyboard event for this purpose. We have been exposed to nsnotification before, as shown in the example above, receiving this nsnotification in the message center, The nsnotification is then captured in the method thekeyboardappeared of the selector and then extracted from the information in the UserInfo for related processing.

Here are some of the other properties of Uitextfield, very interesting


For example, you can set the font size to fit the width of the text box when the text input is many, but the font cannot be reduced indefinitely, and if Adjustsfontsizetofitsidth is set to True, you must set the minimumfontsize dimensions. In addition, you can add some auxiliary functions in the text box, such as emptying the input and so on.

"We all love Paul Hegarty." Stanford IOS8 public class personal note uitextfield text box

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.