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