I have a UIView with a UILabel and a UITextField:
+--------------+
| label |
| |
| +-----------+|
| | textField ||
| +-----------+|
+--------------+
I want to select or focus the textField when I touch the label.
I have a UIView with a UILabel and a UITextField:
+--------------+
| label |
| |
| +-----------+|
| | textField ||
| +-----------+|
+--------------+
I want to select or focus the textField when I touch the label.
Change your container UIView to a UIControl and in your ViewController.viewDidLoad add the following:
textFieldContainer.addTarget(textField,
action: #selector(becomeFirstResponder),
for: .touchUpInside)
This will cause a touchUpInside event on the textFieldContainer to focus the textField
1: Add a UITapGestureRecognizer to your UILabel or your UIView as you wish
2: and handle the action from the tapGesture to fire start editing the textfield on tap.
Don't forget to set the UILabel to userInteractionEnabled = true if you add the tap gesture to the label.