iPhone->动态单元格高度 [英] iPhone -> dynamic cell height
本文介绍了iPhone->动态单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UITableView和一个用Interface Builder设计的单元格. 我在那里有两个标签. 问题在于,标签之一是文本,可以是500个单词或10个单词.
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?
最好的问候.
推荐答案
要知道文本的大小,可以使用以下方法:
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;
这篇关于iPhone->动态单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文