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