0

Right now, I'm using the following code to display my table cell. It is displaying text properly. However, there are some texts which are too long, so I want to display the first 5 lines of the text and then if the user expands the cell, it will display the whole text. I'm stuck because I am not so familiar with the new method in ios 7, boundRectWithSize.

CGSize size = CGSizeMake(self.reviewComments.width,999);
CGSize textRect =[self.reviewComments.text boundingRectWithSize: size options: NSStringDrawingUsesLineFragmentOrigin
                                                     attributes: @{NSFontAttributeName:self.reviewComments.font} context: nil].size ;


float height = textRect.height;
self.reviewComments.height = height;

I tried:

if (height > 150) {
    height = 150;
}

But this way just cuts off the text, even after when I expand it.

UPDATE/EDIT:

I want my cell so that it only displays maybe the first 5 lines of the text if it exceeds 5 lines. The entire text will appear if the cell is expanded.

user3513175
  • 53
  • 1
  • 4

1 Answers1

0

Try this:

float height = ceilf(textRect.height);

Pankaj
  • 397
  • 1
  • 3
  • 13
  • sorry, I've implemented this line. It still does the same thing. I don't understand how this sets a limit for the number of lines. – user3513175 Apr 09 '14 at 18:55