0

How can a textField be resized based on content while using auto-layout in an iOS application written in Swift?

The text field will resize as necessary to fit its content when the view loads as well as while the user is typing. I referred the following link Resize textField Based On Content

but it is not making the field autoresize during typing

Community
  • 1
  • 1
  • If you have clearly referred to the linked mentioned in the question then the answer suggests then you need to use `UITextView` instead of `UITextField`. – Sohil R. Memon Jan 10 '16 at 06:59
  • yes , I have used textview as mentioned in the link..but it is not working as I want..this is my codeclass ViewController: UIViewController { @IBOutlet weak var myTextview: UITextView! var totalLines:CGFloat = 5 var maxHeight:CGFloat? override func viewDidLoad() { super.viewDidLoad() maxHeight = (myTextview.font!.lineHeight * totalLines) myTextview.sizeThatFits(CGSizeMake(myTextview.frame.size.width, maxHeight!)) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } –  Jan 11 '16 at 07:31

1 Answers1

0

If you have clearly referred to the linked mentioned in the question then the answer suggests then you need to use UITextView instead of UITextField.

Well, you can increase the height of UITextView using constraints or you can use this library:

https://github.com/ingridwarrior2901/TextViewAutoHeight-Swift

Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57