自定义cell 自适应高度
#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 自适应高度的更多相关文章
- 自定义cell自适应高度
UITableView在许多App种被大量的应用着,呈现出现的效果也是多种多样的,不能局限于系统的一种样式,所以需要自定义cell 自定义cell呈现的内容也是多种多样的,内容有多有少,所以需要一种能 ...
- 自定义 cell 自适应高度
#import "CommodityCell.h" #import "UIImageView+WebCache.h" @implementation Commo ...
- TableView cell自适应高度-----xib
1.通过xib创建一个cell,将label进行上左下右,进行适配, self.automaticallyAdjustsScrollViewInsets = NO; self.edgesForExte ...
- 【swift,oc】ios开发中巧用自动布局设置自定义cell的高度
ios开发中,遇到自定义高度不定的cell的时候,我们通常的做法是抽取一个frame类,在frame类中预算好高度,再返回. 但是苹果出来自动布局之后...春天来了!!来看看怎么巧用自动布局设置自定义 ...
- Cell自适应高度及自定义cell混合使…
第一部分:UItableViewCellAdaptionForHeight : cell的自适应高度 第二部分:CustomTableViewCell:自定义cell的混合使用(以简单通讯录为例) = ...
- cell自适应高度
MyModel.h #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface MyModel : ...
- IOS XIB Cell自适应高度实现
1.代码实现Cell高度自适应的方法 通过代码来实现,需要计算每个控件的高度,之后获取一个cell的 总高度,比较常见的是通过lable的文本计算需要的高度. CGSize labelsize = [ ...
- 自定义cell的高度
// // RootTableViewController.m // Share // // Created by lanouhn on 15/1/20. // Copyright (c) 2 ...
- iOS之UITableView加载网络图片cell自适应高度
#pragma mark- UITableView - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSI ...
随机推荐
- Silverlight 中 TreeView 的数据绑定
方法一:Silverlight使用XAML标记语言来编写,如果不使用XAML强大的绑定功能,实在是罪过.通过使用绑定,可以将UI与视图模型层分离,有利于系统的维护.作为Silverlight中比较有代 ...
- 【索引】XBox360玩机心得
基础知识 查看XBox360的系统版本信息:http://www.cnblogs.com/duxiuxing/p/4292140.html XBox360光盘游戏的安装: 自制系统 XBox360自制 ...
- Wad Manager的下载和运行
关于WAD版的软件 WAD版的软件分为两种: 独立安装版:程序完全安装在Wii的内置存储空间上,可以在Wii的主界面直接启动软件. Forwarder版:程序安装在Wii的内置存储空间上,同时在SD卡 ...
- spring mvc model.addAttribute页面c:forEach取不到
昨天和今天都在解决一个问题,即: @RequestMapping(value = "/listAccounts", method = RequestMethod.GET) publ ...
- 机器学习实战__安装python环境
环境:win7 64位系统 第一步:安装python 1.下载python2.7.3 64位 msi 版本(这里选择了很多2.7的其他更高版本导致安装setuptools失败,也不知道是什么原因,暂时 ...
- 数据库安全之TDE列加密
透明数据加密(Transparent Data Encryption) TDE - 基于列的加密 由于有了Oracle的TDE-基于列的加密,你所要做的只是定义需要加密的列,Oracle将为包含加密列 ...
- poj2096 Collecting Bugs(概率dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1792 Accepted: 832 C ...
- Neutron中的Service类
Service是OpenStack中非常重要的一个概念,各个服务的组件都以Service类的方式来进行交互. Neutron中的Service类继承自rpc中的Service,总体的继承关系为 neu ...
- [Angular 2] Router basic and Router Params
When we define router in Angualr 2, we use @RouteConcfig() When we want to display component, we use ...
- Ubuntu下php的一些配置问题
1.php.ini的路径: phpinfo()里 Loaded Configuration File:/etc/php5/fpm/php.ini 要修改这个 在/etc/php5/fpm/cgi里也有 ...