#pragma mark - 动态计算cell高度

//计算 返回 文本高度

+ (CGFloat)calsLabelHeightWithContact:(Contacts *)contact

{

//size:   文字最大范围

//options:计算高度 参数

//  NSStringDrawingUsesLineFragmentOrigin:指定 原点 绘制字符串片段起源和基线。

//attributes:文字某个属性 通常是大小

//ios7 获取文本高 方法

CGRect rect = [contact.introduce boundingRectWithSize:CGSizeMake(280, 2000)

options:NSStringDrawingUsesLineFragmentOrigin

attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0f] }

context:nil];

return rect.size.height;

}

//重写contact 的setter方法

- (void)setContact:(Contacts *)contact

{

if (_contact != contact) {

[_contact release];

_contact = [contact retain];

//将获取到的值赋值到控件上,赋值

//1,头像

_headImageView.image = [UIImage imageNamed:contact.headImageName];

//2,名字

_nameLabel.text = contact.name;

//3,电话

_phoneNumberLabel.text = contact.phoneNumber;

//4,性别

_genderLabel.text = contact.gender;

//5,年龄

if (contact.age) {

_ageLabel.text = contact.age;

}else{

_ageLabel.hidden = YES;

}

//6,简介

_introduceLabel.text = contact.introduce;

//计算高度

CGFloat height = [BoyTableViewCell calsLabelHeightWithContact:contact];

//修改高度

CGRect frame = _introduceLabel.frame;

frame.size.height = height;

_introduceLabel.frame = frame;

}

}

#pragma mark - 提供类方法,返回模型内容高度

//使用模型参数,

+ (CGFloat)cellHeightWithContact:(Contacts *)contact

{

CGFloat h = [self calsLabelHeightWithContact:contact];

return 140 + h;

}

//行高

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

{

//1,通过组索引 找出对应的key

NSString *key = _allKeysMutaArray[indexPath.section];

//2,通过可以 查出对应分组

NSMutableArray *array = _allDataMutaDict[key];

//3,通过row 查出 数组对应项

Contacts *c = array[indexPath.row];

//计算出模型的高度

CGFloat h =[BoyTableViewCell cellHeightWithContact:c];

return h;

}

自定义cell 自适应高度的更多相关文章

  1. 自定义cell自适应高度

    UITableView在许多App种被大量的应用着,呈现出现的效果也是多种多样的,不能局限于系统的一种样式,所以需要自定义cell 自定义cell呈现的内容也是多种多样的,内容有多有少,所以需要一种能 ...

  2. 自定义 cell 自适应高度

    #import "CommodityCell.h" #import "UIImageView+WebCache.h" @implementation Commo ...

  3. TableView cell自适应高度-----xib

    1.通过xib创建一个cell,将label进行上左下右,进行适配, self.automaticallyAdjustsScrollViewInsets = NO; self.edgesForExte ...

  4. 【swift,oc】ios开发中巧用自动布局设置自定义cell的高度

    ios开发中,遇到自定义高度不定的cell的时候,我们通常的做法是抽取一个frame类,在frame类中预算好高度,再返回. 但是苹果出来自动布局之后...春天来了!!来看看怎么巧用自动布局设置自定义 ...

  5. Cell自适应高度及自定义cell混合使…

    第一部分:UItableViewCellAdaptionForHeight : cell的自适应高度 第二部分:CustomTableViewCell:自定义cell的混合使用(以简单通讯录为例) = ...

  6. cell自适应高度

    MyModel.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface MyModel : ...

  7. IOS XIB Cell自适应高度实现

    1.代码实现Cell高度自适应的方法 通过代码来实现,需要计算每个控件的高度,之后获取一个cell的 总高度,比较常见的是通过lable的文本计算需要的高度. CGSize labelsize = [ ...

  8. 自定义cell的高度

    // //  RootTableViewController.m //  Share // //  Created by lanouhn on 15/1/20. //  Copyright (c) 2 ...

  9. iOS之UITableView加载网络图片cell自适应高度

    #pragma mark- UITableView - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSI ...

随机推荐

  1. maven项目 打可执行jar包

    1.pom添加 <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</art ...

  2. jQuery(二)

    jQuery学完了!好用! 1.用定时器做的jquery里面的animate效果 <!DOCTYPE html> <html lang="en"> < ...

  3. asp.net using library ClosedXML to export excel

    Reference:  http://closedxml.codeplex.com/ 1. First add refenrence ClosedXML.dll and DocumentFormat. ...

  4. C++中将string类型转换为int, float, double类型 主要通过以下几种方式:

      C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...

  5. Java 编程的动态性,第 7 部分: 用 BCEL 设计字节码--转载

    在本系列的最后三篇文章中,我展示了如何用 Javassist 框架操作类.这次我将用一种很不同的方法操纵字节码——使用 Apache Byte Code Engineering Library (BC ...

  6. table标签

    table标签使我们最常用的的标签,在使用table标签时我们要注意一些其属性,早期我们经常使用table标签对其进行页面布局但是现在我们基本不再使用,由此可见table标签也是非常强大的一个工具. ...

  7. java基本打印练习《我行我素购物系统》

    public class ShoppingSystem{ public static void main(String[] args){ //System.out.println("**** ...

  8. 【网络流#8】POJ 3469 Dual Core CPU 最小割【ISAP模板】 - 《挑战程序设计竞赛》例题

    [题意]有n个程序,分别在两个内核中运行,程序i在内核A上运行代价为ai,在内核B上运行的代价为bi,现在有程序间数据交换,如果两个程序在同一核上运行,则不产生额外代价,在不同核上运行则产生Cij的额 ...

  9. DataGrid 使用模型列后实现点击列名称排序

    DataGrid 使用模型列后实现点击列名称排序 代码如下: <DataGridTemplateColumn Header="型 号" SortMemberPath=&quo ...

  10. HTML CSS样式基础

    一.css 1.什么是css? Cascading Style Sheet 级联样式表 改变样式的一个工具,说白了,就是为了让我们的页面好看, HTML底层封装了css这样一个工具. 2.怎么使用cs ...