Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a multi line expanding UTextField or text input using swift iOS (not using UITextView)

Looking at the behavior of the Apple Messages app, it seems they are using a UITextField for the text input.

The behavior of the placeholder with the cursor appearing at the beginning of the placeholder text (essentially overwriting it) is what I'm basing that assumption on. There is no placeholder for a UITextView that I'm aware of.

I know I can easily use a UITextView and add a placeholder with different color and code the placeholder disappearing when the user starts typing. But I was wondering if there is any way at all to program a UITextField that can have it's frame be fixed in width and expand in height wrapping text.

like image 585
alionthego Avatar asked Dec 02 '22 11:12

alionthego


1 Answers

You can not expand UITextFiled's height.

But you can do this using UITextView ,what you have to do is

Instead of UITextFiled , use UITextView and set ScrollEnabled to false , give UITextView top, bottom, leading and trailing constraint.

Give height constraint to UITextView and set its content hugging priority at low.

now your textview will expand according to text which are insert in it.

Yes, you have to add and manage placeholder logic manually

like image 130
shraddha hattimare Avatar answered May 23 '23 23:05

shraddha hattimare