自定义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 ...
随机推荐
- HTML5 datalist实现suggest功能
1.例子 <!DOCTYPE html> <html> <head> <title>HTML5 datalist tag</title> & ...
- Do's and Don'ts for Android development
Do's and Don'ts for Android development, by Futurice developers Use Gradle and its recommended proje ...
- Nginx+Keepalived主备切换(包含nginx服务停止)
原文地址:http://blog.sina.com.cn/s/blog_79ac6aa80101bmed.html Nginx+Keepalived主备切换(包含nginx服务停止) 环境: VM中4 ...
- 修改CKFinder上传路径
一.CKFinder的若干问题 1.单独使用 ckfinder从原fckeditor分离出来以后可以单独使用,通常我习惯于在工具栏中添加ckfinder.dll,这样以后要使用ckfinder直接从工 ...
- jquery动态添加元素无法触发绑定事件的解决方案。
jquery动态添加元素无法触发绑定的事件的解决方案. ╭(●`∀´●)╯二狗最近在工作中遇到一个问题,即当用jquery动态添加元素后,发现给动态添加的元素却无法触发事件(╯#-_-)╯╧═╧ ( ...
- SecureCRT连接vm中的ubuntu
如何使用SecureCRT连接ubuntu 用secureCRT连接Ubuntu是出现远程系统拒绝访问..经过一翻研究才知道Ubuntu上没有ssh.. 一下为连接过程. 1. 首先要明白什么是ssh ...
- 建立企业内部mavenserver并使用Android Studio公布公共项目
由于Android Studio使用了Gradle构建工具,在library依赖的处理上是将被依赖的library作为一个module引入(拥有一份完整的library拷贝),而Eclipse的ADT ...
- http to https automatic--weblogic/jboss/tomcat--reference
weblogic reference from:http://middlewaremagic.com/weblogic/?p=2019 Many times we want to secure our ...
- js判断访问者是否来自移动端代码
<script type="text/javascript"> function is_mobile() { var regex_match = /(nokia|iph ...
- TreeView绑定无限层级关系类
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); ...