自定义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 ...
随机推荐
- freemarker的非空判断
${price} 判断非空写法就是 ${(price)!}
- 关于SQL的Group By
SELECT col1, col2, col3, sum(col3) from T1 GROUP BY col1, col2, col3, col4 ; 对于含有Group By的Sql语句,需要注意 ...
- [Java Concurrent] 多线程合作 wait / notifyAll 的简单案例
本案例描述的是,给一辆汽车打蜡.抛光的场景. Car 是一辆被打蜡抛光的汽车,扮演共享资源的角色. WaxOnCommand 负责给汽车打蜡,打蜡时需要独占整部车,一次打一部分蜡,等待抛光,然后再打一 ...
- windows shell备忘
1.查找占用80端口的进程idnetstat -aon|findstr "80" 2.查找进程id为"1000"的进程名tasklist|findstr &qu ...
- Unity3D基础学习 NGUI自带Tooltip制作提示文字
简介 NGUI自带的的例子Character中含有一个Tooltip,可以鼠标悬浮到某对象时显示提示文字.非常方便. 创建UITooltip 首先你需要在场景NGUi相机下建立一个空物体我把它命名为T ...
- ionic上拉加载更多解决方法
第一步: $scope.hasmore = true;//是否允许上拉加载 $scope.num = 8;//显示条数 第二步://查询显示内容,查出所有的 $scope.Group = functi ...
- Android Dialog 系统样式讲解及透明背景
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_TRADIT ...
- ListIterator add remove 使用注意
add方法示例 //在最前面添加 List<String> list1 = new LinkedList<String>(Arrays.asList(new String[] ...
- Java多线程——ThreadLocal类
一.概述 ThreadLocal是什么呢?其实ThreadLocal并非是一个线程的本地实现版本,它并不是一个Thread,而是threadlocalvariable(线程局部变量).也许把它命名 ...
- NPOI控件的使用导出excel文件和word文件
public HttpResponseMessage GetReportRateOutput(DateTime? begin_time = null, DateTime? end_time = nul ...