Reputation: 141
First look at the screenshot:
second press the return button, the screenshot for your reference:
after four times click
return
button, the height of text field will not be higher any more.
now here is the question: how can I implement the function of textfield? and what about the background Image behind the text Field , should auto resize too? if there are any solution, let me know! thanks very much----
Upvotes: 1
Views: 753
Reputation: 8944
Make it UITextView
not a text field, track the text changes at shouldChangeTextInRange
of the textView
delegate.
In this method calculate the number of lines (textView.contentSize.height/textView.font.lineHeight), compare it with the previous value to decide whether you need to proceed or just return. If the number of lines is changed, check whether the textView
is already displaying the maximum number of lines (that must be 3 on the image) and based on the results you will change the textView
, it's superview and a button frames (you can also make it animated easily) and probably scroll the text to the change region with scrollRangeToVisible
.
Upvotes: 1