The use of Swift-uitextfield

Source: Internet
Author: User
Tags alphanumeric characters

1, the creation of the text box, there are several styles:

uitextborderstyle.none: No Border    Uitextborderstyle.line: Line Border    uitextborderstyle.roundedrect: Rounded Rectangle border    Uitextborderstyle.bezel: Edge +  Shadow 1234= Uitextfield (Frame:cgrectmake,160 ,(+))// set border style to rounded rectangle Textfield.borderstyle =  UITextBorderStyle.RoundedRectself.view.addSubview (TextField)

2, text box prompt text

textfield.placeholder=" Please enter user name "

3, the text size exceeds the text box length automatically reduces the font size, instead of hiding the ellipsis display

Textfield.adjustsfontsizetofitwidth=true  // text size is automatically resized when text exceeds the width of the text box textfield.minimumfontsize=  // minimum size to reduce

4, Horizontal/Vertical alignment

/** Horizontal Alignment **/textfield.textalignment= . Right//Align Right horizontallyTextfield.textalignment =. Center//Horizontal Center AlignmentTextfield.textalignment =. Left//Horizontal left Justified /** Vertical Alignment **/textfield.contentverticalalignment= . Top//Vertical Upward AlignmentTextfield.contentverticalalignment =. Center//align vertically with centerTextfield.contentverticalalignment =. Bottom//Vertical downward Alignment

5, Background image settings

// first to remove the border style Textfield.background=uiimage (named:"background1");

6, clear the button (the right fork in the input box

Textfield.clearbuttonmode=uitextfieldviewmode.whileediting  // The Clear button appears when editing Textfield.clearbuttonmode=uitextfieldviewmode.unlessediting  // Edit does not appear, the Clear button appears after editing Textfield.clearbuttonmode=uitextfieldviewmode.always  // Always show Clear button

7. Set the keyboard type associated with the text box

Default: The system defaults to the virtual keyboard ASCII capable: Virtual keyboard numbers and punctuation displaying alphanumeric characters: a virtual keyboard URL that displays numbers and punctuation: Displays a virtual keyboard number for easy-to-enter numbers Pad: Display easy to enter the number of virtual keyboard Phone pad: Display a virtual keyboard for easy dial-up calls name phone Pad: Display a virtual keyboard for easy chat dialing email Address: Display a virtual keyboard for easy email input decimal Pad: Display virtual keyboard for entering numbers and decimal points Twitter: Display a virtual keyboard for easy Twitter web Search: Displays a virtual keyboard  that is easy to write on a web page = Uikeyboardtype.numberpad

8. Make the text box get focus when the interface is open, and eject the input keyboard

Textfield.becomefirstresponder ()

9. Make the text box lose focus and retract the keyboard

Textfield.resignfirstresponder ()

10. Set the style of the keyboard return key

// indicates completion input // indicates completion of input and jumps to another page // represents a search // represents a registered user or adds data // means to proceed to the next // represents a Send

11, the response of the keyboard return key

// Set up proxy class firstyviewcontroller:uiviewcontroller,uitextfielddelegate {            var textField = Uitextfield () // Initialize

Implementing Proxy methods

Func Textfieldshouldreturn (Textfield:uitextfield), Bool    {        // closed keyboard         Textfield.resignfirstresponder ()        // print out the values in the text box         print (textfield.text)         returntrue;    }

The use of Swift-uitextfield

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.