0

How could I️ achieve a similar effect to Twitter’s tweet view, where the location label position changes based on how much text is inputted. For instance No text

When there’s no text, the location label is right under the text view but when text is inputted, the label changes its position: text added

How could I️ achieve a similar effect in swift?

ayjoy
  • 155
  • 3
  • 10
  • Note that they are most likely using a custom subclass of UITextView, not UITextField, as UITextField is single line while UITextView supports multi-line. – Jake G Nov 07 '17 at 21:17
  • I️ just fixed that in the question – ayjoy Nov 07 '17 at 21:19
  • Could you set the locations label to the bottom of the label and everytime a line is filled increase the height of the label – Niall Kehoe Nov 07 '17 at 21:21
  • A Mix of Autolayout, with the location label's topAnchor fixed to the textView's bottomAnchor; and a fixed heightAnchor. While making sure the textView expands on line count increase. – jlmurph Nov 07 '17 at 21:23

1 Answers1

1

See this StackOverflow post regarding fitting a UITextView to the content of its text.

In the UITextView shouldChangeTextInRange delegate call, update the frame of the UITextView to fit the text. Then update your location labels frame relative to this new UITextView frame.

Jake G
  • 1,185
  • 9
  • 19