0

I have a table cell that have two pieces of information, one is the article title and is other is the preview of the article. However, the title size changes and may have 1 - 3 lines, so I have to resize the frame of the preview every time.

I want to the make the cell display the maximum number of lines that it can display based on the preview's height and show ... at the end if the information is not completely shown.

I tried:

 cell.previewLabel.text = @"Some data here";
cell.previewLabel.textColor = [UIColor lightGrayColor];
cell.previewLabel.frame  = CGRectMake(50, 20, 200, 95 - cell.titleLabel.frame.size.height  - 5)
[cell.previewLabel sizeToFit];

but it seems to display only 1 lines of information.

When I add

cell.previewLabel.numberOfLines = 0;

The label now have too many lines ( the height of the label is longer than the maximum height I initialized earlier.

How can I fix it?

user959974
  • 379
  • 2
  • 9
  • 25
  • You should find some answers here: http://stackoverflow.com/questions/5041874/uilabels-sizetofit-sizethatfits-ignore-the-numberoflines-property – Rob Reuss Dec 12 '11 at 19:43
  • @RobReuss That fixed most of the problem, thanks! But how to display "..." at the end? – user959974 Dec 12 '11 at 19:58
  • Hopefully this will help with adding the ellipse: http://stackoverflow.com/a/7725835/1090886 – Rob Reuss Dec 12 '11 at 20:34
  • @RobReuss I fixed it by removing the "label.lineBreakMode = UILineBreakModeWordWrap; " line. Thanks for the help. – user959974 Dec 12 '11 at 22:25

0 Answers0