我根据标签高度和标签高度根据文本动态设置tableView单元格高度。当我用空格给出文本时它工作正常(例如:这是针对stackoverflow的问题)。但是当我输入长度不超过两行的文本时(例如ThisisQuestionforstackoverflow)。这是两行,文本从第二行开始,并在最后切割。它采取第一行全空间和第二行像(ThisisQuestionfor .....)。我在设置动态标签高度时出现问题
我使用方法
- +(浮点)calculateHeightOfTextFromWidth:(的NSString *)文本:(UIFont *)withFont:(浮点)宽度:(UILineBreakMode)lineBreakMode
- - (CGFloat的)的tableView :(UITableView的*)的tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
在的cellForRowAtIndexPath
float productNameHeight = [DetailsViewController calculateHeightOfTextFromWidth:warObj1.productName :valueFont : valueWidth :UILineBreakModeWordWrap];
UILabel *productNameValue = [[UILabel alloc] initWithFrame:CGRectMake(xCoordinateStartLocatioForValue,yCoordinateStartLocation,valueWidth,productNameHeight)];
您可以快速帮我。提前感谢
嗨,我已经采取了WordWrap换行符模式,并且我已经设置了label.numberoflines = 0. – 2010-12-14 13:45:56
我曾尝试过字符模式仍然出现同样的问题。 – 2010-12-14 14:02:27
什么是'thisisaverylongstringwithnospaces'的'proudctNameHeight'和'这是一个非常有空格的日志字符串' - 他们是一样的吗?如果它们不同,那么就是你调用'calculateHeightOfTextFromWidth'的方式 – deanWombourne 2010-12-14 14:23:51