我们在使用uitableView的时候,一些简单的cell样式其实是不需要自定义的,但是系统的方法又似乎又无法满足需要,这时候我们就需要在系统上做一些改变来达到我们的需求;

像这种cell,简单分析下,一个textlabel,一个detailTextlabel,一个accview就可以实现。我们需要做的就是一些细节的处理;先上代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:NSStringFromClass([UITableViewCell class])];
} cell.textLabel.textColor = TextblackColor;
cell.textLabel.font = [UIFont systemFontOfSize:[QDFontHelp Font:14]];
if (indexPath.row == 0) {
textString = @"现金分红(默认)";
detailTextString = @"分红所得资金实时发放到钱包";
}else{
textString = @"红利再投资";
detailTextString = @"分红所得资金直接用于购买该基金,将分红转为持有基金份额";
} cell.textLabel.text = textString;
cell.detailTextLabel.text = detailTextString;
cell.detailTextLabel.numberOfLines = 0;
cell.detailTextLabel.font = [UIFont systemFontOfSize:[QDFontHelp Font:12]];
[cell.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.mas_left).offset(WidthScale(15));
make.top.equalTo(cell.mas_top).offset(HeightScale(5));
}];
[cell.detailTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.mas_left).offset(WidthScale(15));
make.right.equalTo(cell.mas_right).offset(-WidthScale(100));
make.top.equalTo(cell.textLabel.mas_bottom);
}];
cell.detailTextLabel.textColor = TextGrayColor;
if (indexPath.row == self.fenghongType) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}
cell.tintColor = APPThemeColor;
return cell;
}

  在这里,我们对系统的textlabel和detailtextlabel进行了重新布局,已避免系统根据我们给出的cell高度进行自动适应;

关于checkmark的颜色,我们可以通过cel的tintcolor来改变!

写到这里,那么我们如何动态返回cell的高度呢,这里我们根据label的内容来返回,代码如下

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

      CGSize size1 = [textString boundingRectWithSize:CGSizeMake(kScreen_width - WidthScale(115), 1000) 
options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:[QDFontHelp Font:14]]} context:nil].size;
CGSize size2 = [detailTextString boundingRectWithSize:CGSizeMake(kScreen_width - WidthScale(115), 1000)
options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:[QDFontHelp Font:12]]} context:nil].size;
return size1.height + size2.height + HeightScale(15); }

  在ios7以后我们不再使用sizetofit来动态返回内容的高度  而使用boundingrect!当然这里还是有一点坑的,在具体使用的时候慢慢摸索吧!

uitableviewcell textlabel detailtextLabel 换行的位置及尺寸问题的更多相关文章

  1. JavaScript获取DOM元素位置和尺寸大小

      在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽略的一部分,要想写出预想效果的JavaScri ...

  2. IOS中调整UI控件位置和尺寸

    1.frame(修改位置和尺寸):以父控件左上角为坐标原点,在其父控件中的位置和尺寸. //frame属性中的坐标点不能直接修改 CGRect tempFrame = self.v.frame; // ...

  3. 获取DOM元素位置和尺寸大小

    JavaScript获取DOM元素位置和尺寸大小 在一些复杂的页面中经常会用JavaScript处理一些DOM元素的动态效果,这种时候我们经常会用到一些元素位置和尺寸的计算,浏览器兼容性问题也是不可忽 ...

  4. jQuery 学习笔记(4)(文本值相关方法、操控CSS方法、位置和尺寸方法)

    1.文本值相关方法 .html() == .innerHTML $("div").html("<span> ...</span>") / ...

  5. DOM元素的位置、尺寸及更多的信息

    一.基本概念 document.documentElement是整个DOM树的根节点,对应的元素就是html.下面将其称作根元素或根节点. document.body,对应的元素是body 二.浏览器 ...

  6. Windows 系统上用 .NET/C# 查找所有窗口,并获得窗口的标题、位置、尺寸、最小化、可见性等各种状态

    原文:Windows 系统上用 .NET/C# 查找所有窗口,并获得窗口的标题.位置.尺寸.最小化.可见性等各种状态 在 Windows 应用开发中,如果需要操作其他的窗口,那么可以使用 EnumWi ...

  7. JS中关于位置和尺寸的api

    HTMLElement.offsetParent 由于offsetTop 和 offsetLeft 都是相对于 offsetParent 内边距边界的,故offsetParent的意义十分重大.off ...

  8. selenium相关:通过location 和 size 获取元素所在像素位置和尺寸,截取图片ROI

    1.实验 #https://captcha.luosimao.com/demo/ chrome default: location 不滚动,直接返回相对整个html的坐标 {'x': 15.0, 'y ...

  9. 原生JS获取元素的位置与尺寸

    1.内高度.内宽度: 内边距 + 内容框 element.clientWidth element.clientHeight 2.外高度,外宽度: 边框 + 内边距 + 内容框 element.offs ...

随机推荐

  1. 子数组最小值的总和 Sum of Subarray Minimums

    2018-09-27 23:33:49 问题描述: 问题求解: 方法一.DP(MLE) 动态规划的想法应该是比较容易想到的解法了,因为非常的直观,但是本题的数据规模还是比较大的,如果直接使用动态规划, ...

  2. DVWA渗透测试环境搭建

    DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法的环境,帮助w ...

  3. Introduction to dnorm, pnorm, qnorm, and rnorm for new biostatisticians

    原文:Introduction todnorm,pnorm,qnorm, andrnormfor new biostatisticians Today I was in Dan’s office ho ...

  4. English Voice of <<Bye Bye Bye>>

    Bye Bye Bye - Lovestoned When i see you, looking back at me 当我看到你回首看我时 Watching this eye still 彼此凝视 ...

  5. 安卓中使用OkHttp发送数据请求的两种方式(同、异步的GET、POST) 示例-- Android基础

    1.首先看一下最终效果的截图,看看是不是你想要的,这个年代大家都很忙,开门见山很重要! 简要说下,点击不同按钮可以实现通过不同的方式发送OkHttp请求,并返回数据,这里请求的是网页,所以返回的都是些 ...

  6. 【异常及源码分析】org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping

    一.异常出现的场景 1)异常出现的SQL @Select("SELECT\n" + " id,discount_type ,min_charge, ${cardFee} ...

  7. java.lang.NoClassDefFoundError: org/springframework/web/context/WebApplicationContext

    一.NoClassDefFoundError与ClassNotFoundException NoClassDefFoundError错误的发生,是因为Java虚拟机在编译时能找到合适的类,而在运行时不 ...

  8. javaweb项目静态资源被拦截的解决方法

    <servlet-mapping> <servlet-name>springMvc</servlet-name> <url-pattern>/*< ...

  9. 为什么样本方差除以(n-1)而不是n ?(自由度)

    不记得第几次看见样本方差的公式,突然好奇为什么要除以(n-1)而不是n呢?看见一篇文章从定义上和无偏估计推导上讲的很清楚https://blog.csdn.net/fuming2021118535/a ...

  10. Oracle PL/SQL异常、存储过程和触发器

    一.异常 1.处理异常 (1)除数不为0 declare b number; begin b:; exception when zero_divide then dbms_output.put_lin ...