转自:http://blog.sina.com.cn/s/blog_a7c44c8801018utb.html
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
}
本文转自 http://mrjeye.iteye.com/blog/1045785
文章来源:http://blog.youkuaiyun.com/csj1987/article/details/6662852
- //初始化label
- UILabel
*label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)]; - //设置自动行数与字符换行
- [label
setNumberOfLines:0]; - label.lineBreakMode
= UILineBreakModeWordWrap; - //
测试字串 -
NSString *s = @"这是一个测试!!!adsfsaf时发生发勿忘我勿忘我勿忘我勿忘我勿忘我阿阿阿阿阿阿阿阿阿阿阿阿阿啊00000000阿什顿。。。"; - UIFont
*font = [UIFont fontWithName:@"Arial" size:12]; - //设置一个行高上限
- CGSize
size = CGSizeMake(320,2000); - //计算实际frame大小,并将label的frame变成实际大小
-
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap]; - [label
setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];
本文介绍如何在 iOS 开发中使用 UITableView 时实现 UITableViewCell 的自适应高度。通过计算文本的实际显示高度来动态调整单元格的高度,确保文本内容完整展示且不浪费空间。
2万+

被折叠的 条评论
为什么被折叠?



