Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewCell textLabel cut off

I see some strange behavior in one of my UITableViewCells. When setting the font of textLabel to an italic font ( [UIFont fontWithName:@"Helvetica-BoldOblique" size:17] ), a few pixels at the end get cut off. It's not looking really bad, but I would like to avoid it. Any suggestions?

Image

I'm using the default UITableViewCell as I only need one UILabel, so no need to subclass. I tried calling [cell.textLabel sizeToFit] after setting the font, but it didn't work.

like image 245
fabian789 Avatar asked Apr 06 '11 15:04

fabian789


1 Answers

As occulus pointed out, the UILabel is not wide enough for the italic text. However, because I'm using the default UITableViewCell, I can not change this. (The textLabel frame seems to be set at some point unknown to me. When -tableView:willDisplayCell:forRowAtIndexPath: is called, it's still CGRectZero.)

So the only solution seems to add a space at the end of my string, as Nick Weaver suggested:

cell.textLabel.text = [NSString stringWithFormat:@"%@ ", cell.textLabel.text];
like image 53
fabian789 Avatar answered Sep 30 '22 16:09

fabian789