I have already put the button and textfield on the storyboard.
I want to put a new textfield under it with code, but I don’t know how.
Do you have a better way?
xcode12.2
@IBOutlet weak var kgTextField1: UITextField!
@IBOutlet weak var repTextField1: UITextField!
@IBOutlet weak var repTextField2: UITextField!
@IBOutlet weak var repTextField3: UITextField!
var addKgTextField : UITextField = UITextField()
override func viewDidLoad() {
super.viewDidLoad()
addKgTextField.frame = CGRect(x: 20, y: 100, width: 60, height: 34)
}
@IBAction func didTapAddSetButton(_ sender: Any) {
self.view.addSubview(addKgTextField)
self.view.reloadInputViews()
}
2
Answers
This code solve your problem.
You could also add another Textfield and change its visibility when the button is pressed.