1

Being an android developer, when I want the width and the height of something to wrap its content I simply change the width and height value in the inspector to "wrap content" and it's done. it does not seem as simple as that in Xcode. What I'm trying to achieve is the design of a messaging app, i.e.:

enter image description here

As you see each row has it own height and width of the UILabel according to the text size.

I tried to look for solutions using auto layout and stuff but with no success! I was able to have dynamic height but the width of the UILabel is always stretched when used and I'm kinda lost. any straightforward solution in order to achieve this or a hint on how to use the auto layout to get the desired results ? Thank you.

Joseph Hajjar
  • 138
  • 2
  • 12
  • I hope this is what you want -: https://stackoverflow.com/questions/30450434/figure-out-size-of-uilabel-based-on-string-in-swift – Tushar Sharma Aug 27 '17 at 15:50

1 Answers1

0

labelName.sizeToFit()will change the frame of the label to fit the text

OverD
  • 2,612
  • 2
  • 14
  • 29