I have a UITableView where each row may have a label anywhere from no lines to any number of lines (realistically 3-4). I am wanting the row to be expanded based on the UILabelView contents.
I have this so far:
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat height = 60.0;
UIFont *font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:10.0];
NSString *text = reminder.notes; //the text that will be in the UiLabelView
CGFloat notesHeight = [text sizeWithFont:font
constrainedToSize:CGSizeMake(250.0, 4000.0)
lineBreakMode:UILineBreakModeTailTruncation].height;
height += notesHeight;
return height;
}
I still get screwy results. What can I do to accomplish my goal?
Thank you
you are using
UILineBreakModeTailTruncationas lineBreakMode which will always result in a single line andsizeWithFont:constrainedToSize:lineBreakMode:will then return the needed size of that single line.Try
UILineBreakModeWordWrapinstead.edit: I hope you have set the
numberOfLines-property of aUILabelto0(zero) so that your label is able to draw many lines.