Adding UITextField on UIView Programmatically Swift

前端 未结 9 1458
不知归路
不知归路 2021-01-30 06:42

I\'m new to Swift and iOS programming. I was trying to create a UITextField programmatically using Swift but couldn\'t get it quite right. Also how do you change it

9条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 07:24

    Updated for Swift 3 and Xcode 8.2

        let stepsTextField = UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40))
        stepsTextField.placeholder = "Enter text here"
        stepsTextField.font = UIFont.systemFont(ofSize: 15)
        stepsTextField.borderStyle = UITextBorderStyle.roundedRect
        stepsTextField.autocorrectionType = UITextAutocorrectionType.no
        stepsTextField.keyboardType = UIKeyboardType.default
        stepsTextField.returnKeyType = UIReturnKeyType.done
        stepsTextField.clearButtonMode = UITextFieldViewMode.whileEditing;
        stepsTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.center
    

提交回复
热议问题