0

I have a problem with UILabel. I want to show the comments multiline. But they are single line. This is my code:

CGRect currentFrame = comment.frame;
CGSize max = CGSizeMake(comment.frame.size.width,20000.0f);
CGSize expected = [comment.text sizeWithFont:[UIFont systemFontOfSize:10.0] constrainedToSize:max lineBreakMode:UILineBreakModeWordWrap];
currentFrame.size.height = expected.height;
comment.frame = currentFrame;
comment.numberOfLines = 0;
[comment sizeToFit];

But the result is not good. Where am I wrong?

2 Answers2

0

Your code is okay, but you should add this line in your code to get multi line

comment.lineBreakMode = UILineBreakModeWordWrap;
Sumanth
  • 4,913
  • 1
  • 24
  • 39
-1

I think you should increase the number of lines like

comment.numberOfLines = 2  /* or more */

So when the text size increase the width of label it will be multy line but keep in mind about font size and lable size ration

Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134
Aashish
  • 1
  • 1