Kerby Jean
Kerby Jean

Reputation: 207

How to resize UITextField height as user types in Swift

I want to change the textField height as the user types in it. How can I do it?

I don't want to use a TextView.

Upvotes: 1

Views: 361

Answers (1)

Aline Kolczycki Borges
Aline Kolczycki Borges

Reputation: 172

Every UITextField comes with an action Editing changed, you can drag and drop as an action to your class.

In this method, you can probably change the constraint that defines the height of the UITextField. Make sure to call self.view.layoutIfNeeded() to update the constraint you just changed. For example:

@IBAction func editingChanged(sender: AnyObject) {
    editTextHeight.constant += 2.0
    self.view.layoutIfNeeded()
}

Upvotes: 4

Related Questions