views:

52

answers:

1

I am trying to use this method to draw a string into a custom UITableViewCell.

   [self.text drawInRect:TEXT_RECT withFont:font lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];

The problem is that if the text is too long, the text is actually tail truncate but it doesn't display the "..."

If I use the drawInPoint

[self.text drawAtPoint:CGPointMake(60, 0) forWidth:200 withFont:font minFontSize:15 actualFontSize:nil lineBreakMode:UILineBreakModeTailTruncation
    baselineAdjustment:UIBaselineAdjustmentAlignBaselines];

Then, I get the "..." but now it make all of my text one line, so the quite long text will get truncated too soon. For example:

If I have the text "Hello all, here is my first book". If I use drawInRect, then I can display it in 2 lines, but if I use drawAtPoint, I only see the first line like : "Hello all, here ..."

So, any help to make either method work will be appreciated

A: 

UILineBreakModeTailTruncation only truncates the last line of text. Is TEXT_RECT big enough to hold multiple lines of text? What appears to be tail truncation might just be a rect that isn't tall enough.

James Huddleston
Here is my TEXT_RECT : #define TEXT_RECT CGRectMake (60, 0, 200, 200) I think that it is big enough to contains any text. In my cell, it can contains text up to 2 lines
vodkhang
That sure looks big enough. How big is the `UIView` in which you're doing the custom drawing? If it is smaller than two lines of text and has `clipsToBounds` set to `YES`, it might be clipping your drawing.
James Huddleston
I am drawing inside the UITableViewCell and the height of the cell is 44, I think the clipsToBounds is YES. Then, how can I display "..." programmatically
vodkhang
If you want the text on two lines, you could make your `UITableViewCell` taller. You could also avoid custom drawing altogether by adding a two-line `UILabel` to the cell.
James Huddleston
Seems that this is the only solution. I want to draw because the performance for scrolling is bad, and I don't want to mix the drawing code and the setting ones
vodkhang
If performance for scrolling is bad you should look at making the subviews of the UITableViewCell opaque. Also make sure you are using dequeueReusableCellWithIdentifier correctly.
aegzorz
+1 aegzorz. The only other thing I can think of that might be causing the drawing problems is that another (white opaque) view could be covering up the second line of text. However, if the real underlying issue is bad scrolling performance, consider the techniques mentioned above first.
James Huddleston