Adding UITextField on UIView Programmatically Swift

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

    Make sure you're in the viewDidLoad() and then simply add the following code to produce a textField:

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

提交回复
热议问题