Dynamically adjusting text box to fit text

Hi was wondering if anyone knows a good strategy to adjust a text box to fit text.
any ideas welcome.

Currently I am thinking to:

  1. counting the length of text,
  2. chopping it into lines (add
    )
  3. counting the lines and
  4. stretch the text box to fit.

But I am hoping there is a better way!

I want to then move a button to fit at the bottom of my text box.

any ideas welcome.
Thankyou!