1.先cell自适应

可以先拿到 这个lable里文字的高度

//lable自适应的高度
-(CGFloat)heightWithString:(NSString *)aString
{ CGRect r = [aString boundingRectWithSize:CGSizeMake(self.tableView.frame.size.width - 28, 20000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:FourT3GongNengZiHaoFont} context:nil]; return r.size.height;
}

在cell的高度返回方法里面调用方法

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [ActiviteDetail2TwoCell cellHeight:[self heightWithString:_activityInfoNewModel.activityDes]]; }

在cell里填写此cell需要的高度

+(CGFloat)cellHeight:(CGFloat)height
{ return 72+height;
}

此时cell可以根据文字的高度 而适应高度了

那么cell里的lable的高度怎么设置??

正常在初始化里写正常的高度就可以

    self.detailLable.frame = CGRectMake(14, CGRectGetMaxY(self.titleLable.frame)+28+1, CurrentScreenWidth-28, 23);

在cell里写一个改变这个detail的方法

//赋值 and 自动换行,计算出cell的高度
-(void)setDetailLableText:(NSString *)text
{
//获得当前cell高度
CGRect frame = [self frame];
//文本赋值
self.detailLable.text = text;
//设置label的最大行数
self.detailLable.numberOfLines = 10;
CGSize size = CGSizeMake(CurrentScreenWidth-14-30-14, 1000);
CGSize labelSize = [self.detailLable.text sizeWithFont:self.detailLable.font constrainedToSize:size lineBreakMode:NSLineBreakByClipping];
self.detailLable.frame = CGRectMake(self.detailLable.frame.origin.x, self.detailLable.frame.origin.y, labelSize.width, labelSize.height); //计算出自适应的高度
frame.size.height = labelSize.height; self.frame = frame;
}

出来再cell的赋值里面调用这个方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ ActiviteDetail2TwoCell *cellTwo = [tableView dequeueReusableCellWithIdentifier:@"ActiviteDetail2TwoCell" forIndexPath:indexPath];
cellTwo.selectionStyle = UITableViewCellSelectionStyleNone; [cellTwo setDetailLableText:_activityInfoNewModel.activityDes]; }

lable的行间距设置

 if (cellTwo.detailLable.text!=nil) { //这里要判断一下 改label不为空的时候  不判空 会蹦掉
NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cellTwo.detailLable.text];
NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle1 setLineSpacing:3];
[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cellTwo.detailLable.text length])];
[cellTwo.detailLable setAttributedText:attributedString1];
[cellTwo.detailLable sizeToFit];
}

lable 根据宽度适应字体

titleLabel.adjustsFontSizeToFitWidth = YES;

lable 以及cell的高度自适应的更多相关文章

  1. [Swift通天遁地]二、表格表单-(3)在表格中嵌套另一个表格并使Cell的高度自适应

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  3. 转:iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  4. iOS 开发中单元格cell高度自适应

    高度自适应分下面两种情况 1.用代码自定义的cell 用代码自定义的cell,cell高度自定义需要我们手动的去计算每个cell的字符串高度.然后返回对应的高度即可. 2.用XIB 或者 StoreB ...

  5. 关于TableViewCell高度自适应问题的整理

    TableViewCell高度自适应在网上有很多资料,我只想找出最最最简单的一种方法. 首先梳理一下思路.说到TableViewCell我们第一个想到的问题或许就是cell的复用问题. 1.  [se ...

  6. uitableviewcell高度自适应笔记

    今天看了几篇uitableviewcell高度自适应的文章,大体分为两种方式. 第一种方式,cell里面有label,在cellforrow绘制的时候计算Label的可能高度,并且在此时重新计算cel ...

  7. UITableViewCell高度自适应探索--AutoLayout结合Frame

    UITableViewCell高度自适应探索--UITableView+FDTemplateLayoutCell地址: http://www.jianshu.com/p/7839e3a273a6UIT ...

  8. UITableViewCell 高度自适应

    UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看sunny的这篇文章介绍,今天主要和大家分享下我在使用systemLayout ...

  9. autolayout 高度自适应

    https://lvwenhan.com/ios/449.html #import "ViewController.h" #import "MyTableViewCell ...

随机推荐

  1. STM32-NVIC中断管理实现[直接操作寄存器]

    源:stm32 NVIC中断管理实现[直接操作寄存器]     cortex-m3支持256个中端,其中包含了16个内核中断,240个外部中断.stm32只有84个中断,包括16个内核中断和68个可屏 ...

  2. java中基本类型占用字节数

    之前一直使用c/c++开发c中各种类型占用的位数和java还是有区别的,特地找了篇文章过来对比下. 在处理网络协议的时候需要注意 在Java中一共有8种基本数据类型,其中有4种整型,2种浮点类型,1种 ...

  3. mvc中上传图片到指定文件夹中

    前台: @using (Html.BeginForm("AddImg", "UpFileImg", FormMethod.Post, new { enctype ...

  4. java实现——006重建二叉树

    public class T006 { public static void main(String[] args){ int pre[] = {1,2,4,7,3,5,6,8}; int in[] ...

  5. AppBarLayout学习笔记

    LinearLayout的子类 AppBarLayout要点: 功能:让子View(AppBar)可以选择他们自己的滚动行为. 注意:需要依赖CoordinatorLayout作为父容器,同时也要求一 ...

  6. SQLite高级:一库建多表,封装类

    package eoe.database; import android.content.Context; import android.database.sqlite.SQLiteDatabase; ...

  7. bitmap资源回收

    这个问题哎,困扰本宫一天! bitmap不完全解决method: http://blog.csdn.net/hahahacff/article/details/8540942 http://blog. ...

  8. Sqlserver 时间字段批量增加

    update dt_article_attribute_value set end_time = dateadd(mi,30,start_time) create table tb(dt dateti ...

  9. Mongodb 导出json 和csv 格式数据

    导出到json: $ mongoexport.exe  -d TestDB -c TestCollection -o  ./test.json 导出到csv: If you want to outpu ...

  10. HTML5学习笔记一:与html4的区别(整合)

    一 语法的改变 1.1 HTML5中标记方法 1.内容类型(ContentType):扩展符仍为“.html”或".htm",内容类型仍是“text/html”. 2.DOCTYP ...