当前位置: 首页 > news >正文

泰州做兼职的网站/南京seo域名

泰州做兼职的网站,南京seo域名,网站模板 商标,做cosplay网站教程Demo下载 在UITableView中要想cell自适应行高,其实就是UIlabel上的文本根据文本以及文本字体大(即boundingRectWithSize方法)来进行高度的调整,从而重新对cell上UIlabel下面的其他控件进行frame上的y的改变,达到cell上…

Demo下载

在UITableView中要想cell自适应行高,其实就是UIlabel上的文本根据文本以及文本字体大(即boundingRectWithSize方法)来进行高度的调整,从而重新对cell上UIlabel下面的其他控件进行frame上的y的改变,达到cell上的布局调整,高度的自适应,代码如下:

在VC文件中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{MessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MessageListCell"];if(!cell){cell = [[MessageListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MessageListCell"];cell.selectionStyle = UITableViewCellSelectionStyleNone;}if (arr_messlist.count > 0){if (indexPath.row < arr_messlist.count) {//显示cell数据NSString *str = arr_messlist[indexPath.row];[cell setByString:str];}}return cell;
}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{//获取当前行文本内容NSString *str = arr_messlist[indexPath.row];//自适应高度CGSize size = CGSizeMake(Wi - f_CalcRealWidthByiPhone6(10) * 2 - f_CalcRealWidthByiPhone6(5) * 2, 0);CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0f]} context:nil];CGFloat messH = f_CalcRealHeightByiPhone6(20) + rect.size.height + f_CalcRealHeightByiPhone6(15);return f_CalcRealHeightByiPhone6(20) * 2 + messH;
}

在cell文件中

#pragma mark - 显示数据
- (void)setByString:(NSString *)string
{//1、自适应高度[self refreshHeight:string];//2、赋值lbl_time.text = @"2016-09-20";lbl_title.text = @"文本信息";lbl_content.text = string;
}- (void)refreshHeight:(NSString *)string
{//内容NSString *str = string;//自适应高度CGSize size = CGSizeMake(Wi - f_CalcRealWidthByiPhone6(10) * 2 - f_CalcRealWidthByiPhone6(5) * 2, 0);CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:FONT_S_14} context:nil];CGFloat messH = f_CalcRealHeightByiPhone6(25) + rect.size.height + f_CalcRealHeightByiPhone6(10);//信息背景v_mess.frame = CGRectMake(f_CalcRealWidthByiPhone6(10), f_CalcRealHeightByiPhone6(40), Wi - f_CalcRealWidthByiPhone6(10) * 2, messH);//信息内容lbl_content.frame = CGRectMake(f_CalcRealWidthByiPhone6(5), f_CalcRealHeightByiPhone6(25), Wi - f_CalcRealWidthByiPhone6(15) * 2, rect.size.height);
}

在这里,要切记如下几点:

1、设置文本行数

lbl_content.numberOfLines =0;

2、设置文本字体要和boundingRectWithSize中的字体保持一致

lbl_content.font =FONT_S_14;

3、如果还有控件在label下方,同时需要重新改变label下方控件的y坐标,其他不变

4、如果cell使用的xib文件拖拽的,还需要将这两个勾选去掉,因为这是自动调节,那我们改变的值不起作用,且重新布局时不要使用Masonry布局,使用它也不起作用,还是老老实实的使用frame吧

   

源码下载Demo下载

效果图如下:



http://www.jmfq.cn/news/4756969.html

相关文章:

  • 求和萝莉做的网站/新媒体seo培训
  • 做网站框架/seo兼职招聘
  • 怎么在网站上做签到/百度小程序优化
  • 做批发是国际购物网站有哪些/网站怎么优化关键词快速提升排名
  • 如何开发电子商务网站/北京网络推广有哪些公司
  • 百度网站自然排名优化/谷歌海外推广
  • wordpress带个人中心/seo行业岗位
  • 企业 网站 程序/推广链接
  • 专业制作网站多少钱/上海网站建设方案
  • 旅游网站开发的作用/顾问
  • 自己的网站怎么做seo/东莞新闻最新消息今天
  • 网站建设代码生成器/网络产品及其推广方法
  • 负责加强局网站建设/浙江seo外包
  • wordpress两种语言主题/天津seo霸屏
  • 做网站同行/站长工具综合查询ip
  • 做企业网站收费价格/广告营销案例100例
  • 济南58同城网/seo任务
  • 爱站查询/公司模板建站
  • 网站导航栏注明做/免费手机网站建站平台
  • 在线制作印章图片/seo 页面
  • 做企业网站用php/郑州网站优化
  • 怎么免费做网站/世界大学排名
  • wordpress 获取备案号/广州seo和网络推广
  • 旅游网站html5代码模板/网络营销方案
  • discuz插件/广州seo效果
  • 美国一级a做爰片免费网站 视频/百度 营销推广多少钱
  • 网站开发违法/360网站安全检测
  • 厦门最早做网站的公司/seo全称是什么
  • 罗田网站建设/微博seo排名优化
  • 佛山公司网站建设价格/网上推广企业