UITableView的cell 动态 定义 高度
来源:互联网 发布:sqlserver 2008r2.net 编辑:程序博客网 时间:2024/05/02 02:36
转自 http://blog.csdn.net/jinglijun/article/details/8333827
首先在
UITableView 的代理方法中算出每个cell 的真实高度,然后设置便ok。如下:
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- UITableViewCell *cell;
- if (indexPath.section==1) {
- UITableViewCell *newsCell = [DataTable dequeueReusableCellWithIdentifier:@"newsCell1"];
- if (newsCell==nil) {
- newsCell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
- reuseIdentifier:@"newsCell1"]autorelease];
- }
- CGRect cellFrame = [newsCell frame]; //定义的cell 的 frame
- cellFrame.origin = CGPointMake(0,0);
- UILabel *productLabel31=(UILabel *)[newsCell.contentView viewWithTag:111143];
- if (!productLabel31) {
- productLabel31=[[UILabel alloc]initWithFrame:CGRectMake(cellXOffset,6,sectionTwoLabelWidth,10)];
- productLabel31.backgroundColor=[UIColor clearColor];
- productLabel31.tag=111143;
- productLabel31.numberOfLines=0;
- productLabel31.lineBreakMode=UILineBreakModeWordWrap;
- productLabel31.text=[normalTitleArray objectAtIndex:indexPath.section];
- productLabel31.font= [UIFont systemFontOfSize:cellProductLabelFont];
- CGSize size = [productLabel31.text sizeWithFont:[UIFont systemFontOfSize:cellProductLabelFont] constrainedToSize:CGSizeMake(sectionTwoLabelWidth, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap]; //算出cell 的具体高度
- productLabel31.frame=CGRectMake(cellXOffset,6,sectionTwoLabelWidth,size.height);
- [newsCell.contentView addSubview:productLabel31];
- [productLabel31 release];
- }
- cell = newsCell;
- cellFrame.size.height = productLabel31.frame.origin.y+productLabel31.frame.size.height +2; // 改变cell 的frame
- [cell setFrame: cellFrame]; // 改变cell 的frame
- }
- cell.selectionStyle=UITableViewCellSelectionStyleNone;
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
- return cell.frame.size.height;
- }
这样cell就可以伴随你cell 内容的多少而 任意改变高度了。
效果:
- UITableView的cell 动态 定义 高度
- UITableView的cell 动态 定义 高度
- iOS UITableView Cell的动态高度实现
- iOS8 UITableView动态加载cell的高度
- 【iOS】UITableView 动态确定cell的高度
- UITableView动态改变Cell高度
- UITableView动态改变Cell高度
- 几种设置UITableView的cell动态高度的方法
- UITableView 如何不动态计算返回的cell 的高度
- UITableView 如何不动态计算返回的cell 的高度
- UITableView中动态返回自定义cell的高度
- 动态设置UITableView的cell高度(old)
- Swift之动态适配UITableView的cell高度
- UITableView的cell自适应高度
- UITableView的cell自适应高度
- 动态改变UITableView中的Cell高度
- iOS UITableView Cell动态高度(使用AutoLayout)
- UITableView使用AutoLayout动态计算cell高度
- iOS 中如何添加应用自己的字体
- iOS 17个常用代码整理
- Unity Application Block 学习手册3
- java集合 hashmap hashtable weakhashmap linkedlist arraylist vector
- linux命令排行榜
- UITableView的cell 动态 定义 高度
- js 中的alert title 在 iOS 中如何消失
- 禁止UIWebView滚动和回弹方法
- 坑爹的 APNS 回调方法didReceiveRemoteNotification
- 如何使用iOS Keychain存储用户敏感信息
- iOS开发之使用lipo命令制作模拟器与真机通用静态库
- Android Wifi方法大全
- 如何分析iOS app crash 报告
- iOS6 UITableView的背景颜色的修改