如何根据表中的内容设置行高? [英] How to set row height based on its content in table?

查看:115
本文介绍了如何根据表中的内容设置行高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,表具有固定的行高,但根据我的要求,我需要根据其中的内容设置每一行的高度。

Generally, table has a fixed row height but according to my requirements I need to set height of each row according to content within it.

任何人都可以建议我一些解决方案?

Can anyone suggest me some solution for it?

感谢,

Miraaj

推荐答案

感谢您的建议和帮助。现在使用 tableView中的以下代码解决此问题:heightOfRow:

Thanks all for your suggestions and help. This problem is now resolved using following code in tableView:heightOfRow:

float colWidth = [[[tableView tableColumns] objectAtIndex:1]width];

NSString *content = [[[tempArray objectAtIndex:row] objectForKey:@"tValue"] string];

float textWidth = [content sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"Lucida Grande" size:15],NSFontAttributeName ,nil]].width;

float newHeight = ceil(textWidth/colWidth);

newHeight = (newHeight * 17) + 13;
if(newHeight < 47){
    return 47;
}   
return newHeight;

这篇关于如何根据表中的内容设置行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆