UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText = @"Go get some text for your cell.";
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}
---------------------------
other mehod the solve this problem
UILabel* label = [[UILabel alloc] initWithFrame:cell.frame];
label.numberOfLines = <...an appriate number of lines...>
label.text = <...your text...>
[label sizeToFit];
[cell addSubview:label];
[label release];
分享到:
相关推荐
利用纯代码实现,两种最容易实现自适应高度的方法。一看就能学会。
UITableviewCell高度自适应
UITableViewCell自适应高度,利用UITableView的UITableViewAutomaticDimension的特性,结合masonry实现纯代码cell自适应高度。
很好用封装好的 只需要cocoapods导入uitableview fd就可以用了
在开发中,uitableView 会经常用到,作为实现tableView展示数据的cell 也就显示出了非同一般的作用,经常,我们从网络上解析到数据之后,每条数据有多有少,这就要求cell有不同的高度,自适应高度的要求由此产生,...
最近在研究UITableViewCell高度的自适应,在网上找到了一个国内人员开发的工具类,自己下载下来研究了一下,感觉非常不错,用起来也非常方便,这是高手的博客地址...这是工具类的git地址...
作者rasping,源码AutoLayoutCellDemo,在开发中使用UITableView时经常会遇到,UITableViewCell的高度随cell的内容变化而变化。这就导致我们在添加cell之前需要写一大堆的代码去计算cell内容的高度,然后再确定cell...
UITableView,cell 得自适应
iOS的cell行高自适应是个非常常见的需求,也是一个非常简单的需求,之前我遇到过很多小伙伴不知道怎么来实现,在这里就一步步的来分析一下,供大家参考。 问题分析 其他的实现场景就不说了,我们现在来分析一下具体...
UITableView+FDTemplateLayoutCell cell自适应高度框架 SDWebImage 只是用了UIImageView + WebCache 使用说明 克隆项目后,需要使用Cocoapods updte/install 部分图片素材来源于融云IMKit,如需将TLMessage用于...
// cell布局设置好之后调用此方法就可以实现高度自适应(注意:如果用高度自适应则不要再以cell的底边为参照去布局其子view) [cell setupAutoHeightWithBottomView:_view4 bottomMargin:10]; 2. >> 设置 tableview...
状态栏20键盘高度216导航44 最少2位 补0 // UIColor *color2 = [[UIColor alloc] initWithRed:0 green:1 blue:0 alpha:1]; // button setTitle:@"点我吧" forState:UIControlStateNormal]; // [button addTarget:...
感谢GraphKit作者,demo中的绘图功能大部分实现采用他的方法和思路做的并进行了一些小改! ... 其实想到要实现它的方法很多,...当控件放大时cell上文字实现自适应宽高 按钮实现弹性放大效果,进度条动画比例等效果