I have a UITableView and a Cell which I design with Interface Builder. I have two labels there. The problem is, that one of the labels is text which can be 500 words or 10 words.
So I need a dynamic cell height. How can I 开发者_如何转开发handle this, because otherwise I have empty space or the cell height is not enough.
Perhaps someone has an idea how to do this?
Best Regards.
To know the size of your text, you can use this method:
- (CGFloat)measureTextHeight:(NSString*)text fontName:(NSString*)fontName fontSize:(CGFloat)fontSize constrainedToSize:(CGSize)constrainedToSize {
CGSize mTempSize = [text sizeWithFont:[UIFont fontWithName:fontName size:fontSize] constrainedToSize:constrainedToSize lineBreakMode:UILineBreakModeWordWrap];
return mTempSize.height; }
Then you can set your size cell with:
-(CGFloat)tableView:(UITableVIew*)tableView heightForRowAtIndexPath(NSIndexPath *)indexPath;
-(CGFloat)tableView:(UITableVIew*) tableView heightForRowAtIndexPath(NSIndexPath *) indexPath
{
//here u can check the row number and ur labels and return ur custom height.
}
精彩评论