Swift textfield代码生成

15. March 2016 Swift 0
var textField = UITextField(frame: CGRectMake(10, 160, 200, 30))
        textField.borderStyle = UITextBorderStyle.RoundedRect //圆角矩形边框
        textField.borderStyle = UITextBorderStyle.None //无边框
        textField.borderStyle = UITextBorderStyle.Line //直角边框
        textField.borderStyle = UITextBorderStyle.Bezel //边线加阴影
        textField.placeholder = "请输入用户名"
        textField.text = "lijian"
        textField.adjustsFontSizeToFitWidth = true //自动调小文字全部显示出来
        textField.minimumFontSize = 14 //指定最小可缩小的字号
        textField.textAlignment = NSTextAlignment.Right//向右对齐
        textField.textAlignment = NSTextAlignment.Center //居中对齐
        textField.textAlignment = NSTextAlignment.Left //向左对齐
        textField.contentVerticalAlignment = UIControlContentVerticalAlignment.Top //向上对齐
        textField.returnKeyType = UIReturnKeyType.Done //设置键盘return
        textField.clearButtonMode = UITextFieldViewMode.WhileEditing //编辑的时候出现叉号
        textField.clearButtonMode = UITextFieldViewMode.UnlessEditing//完成编辑才出现清楚按钮
        textField.clearButtonMode = UITextFieldViewMode.Always //一直显示清楚按钮
        self.view.addSubview(textField)

Leave a Reply

Your email address will not be published. Required fields are marked *