Adding UITextField on UIView Programmatically Swift

前端 未结 9 1288
不知归路
不知归路 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:22

    Write the code in viewDidLoad() and implement delegate UITextFieldDelegate

    let _textField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200.00, height: 40.00))
    _textField.backgroundColor = UIColor.redColor()
    _textField.text = "some string"
    _textField.delegate = self
    _textField.borderStyle = UITextBorderStyle.Line
    self.view.addSubview(_textField)
    

提交回复
热议问题