"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.


The Uitextfield (text box) and label look like, but the text box is able to be edited. Be aware of using text boxes in the UI. Because the input text on the simulator is able to use the computer keyboard. And on the real machine. The user can only use the virtual keyboard. So be careful. In addition, the text size, color, and so on can also be set, as in the label.

Each time we click the text box to start typing, the text box becomes the first responder on the page. At this point the virtual keyboard will slide out of the bottom, with our input, as if the text box in the Web development has been focused. You can use Becomefirstresponder to specify that an object becomes the first responder of the current page. Assuming that the keyboard disappears, we just need to make the text box once again the first responder, using Rsignfirstresponder.

At the end of our input, click the return key on the keyboard (of course. This key displays the text that can be edited, which triggers the proxy method Textfieldshouldreturn. Typically you will write Sender.resignfirstresponder in this method to close the virtual keyboard.


When the editor is finished, it says that TextField once again becomes first responder. There is also a proxy method called Textfielddidendediting.

Uitextfield can also act as a UI controller, just like a button, we can trigger the target and action via a button, and we can trigger some action and target via a uitextfield. Only the events and buttons that are triggered are different.

Take 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 it up, such as the name of the Returnbutton display, ciphertext input, and so on. These properties can also be set in the property inspector.


When the keyboard slides out, it may obscure other views on the page. We need to adapt these views to the position of the keyboard (especially the text box itself) and use the nsnotification associated with the keyboard event for this purpose. We've been in touch with Nsnotification before. As seen in the example above, receive this nsnotification in the message center, then capture the nsnotification in the corresponding method thekeyboardappeared of the selector and then extract the information from the UserInfo for related processing.

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


For example, you can set the font size to fit the width of the text box when there is a lot of text input. However, this font can not be reduced indefinitely. Assuming Adjustsfontsizetofitsidth is set to True, be sure to set the size of the minimumfontsize. 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

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.