Basic Property settings of the swift-UITextfield control and uitextfield attributes

Source: Internet
Author: User

Basic Property settings of the swift-UITextfield control and uitextfield attributes

 

// 1. initialize UITextField

Let userName = UITextField (frame: CGRectMake (0,100,100,100 ));

 

// 2. Add the userName text box to the current view

Self. view. addSubview (userName );

 

// 3. text box displays text by default

UserName. placeholder = "Enter your mobile phone number ";

 

// 4. Set the font size

UserName. font = UIFont. systemFontOfSize (16 );

 

// 5. When editing, the Delete small icon appears on the right side of the text box, which is frequently used on the login interface.

UserName. clearButtonMode = UITextFieldViewMode. WhileEditing;

 

// 6. If you need to set the border color of the text box, you need to set the color and border size at the same time, otherwise there will be no border effect

UserName. layer. borderColor = UIColor. blackColor ();

UserName. layer. borderWidth = 1;

 

// 7. Set the rounded corner of the text box

UserName. layer. cornerRadius = 5;

 

// 8. Sometimes you need to add an image to the Left view of the text box.

// 8.1 Add User Name left view

Let NameLeftView: UIView = UIView (frame: CGRectMake (0, 0, 40, 60 ));

Let namePic: UIImageView = UIImageView (frame: CGRectMake (5, 20, 20 ));

NamePic. image = UIImage (named: "iconfont-phone.png ");

NameLeftView. addSubview (namePic );

UserName. leftView = NameLeftView;

// The following code indicates when the image is displayed.

UserName. leftViewMode = UITextFieldViewMode. Always;

// 9. The characters in the text box are displayed *

UserName. secureTextEntry = true;

// 10. Border rounded corner

UserName. borderStyle = UITextBorderStyleRoundedRect;

// 11. Set the keyboard style userName. keyboardType = UIKeyboardTypeNumberPad; (digital keyboard) // 12. Set the UITextField proxy userName. delegate = self; // This is my project login interface

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.