不等高cell搭建(二)

// 给模型的top_cmt属性赋值调用
- (void)setTop_cmt:(NSArray *)top_cmt
{
_top_cmt = top_cmt;
if (top_cmt.count) {
_commentItem = top_cmt.firstObject;
}
}
// key:哪个数组需要转换
+ (NSDictionary *)mj_objectClassInArray
{
return @{@"top_cmt":@"XTCommentItem"};
}
if (item.commentItem) { // 先判断有没有最热评论,有评论才需要计算
CGFloat commentH = ; 声音评论,高度是确定的
注意点:以后只要判断字符串有没有内容,用长度
if (item.commentItem.content.length) { // 有内容,就是文本评论
根据文字的高度来计算评论的高度
NSString *totalStr = [NSString stringWithFormat:@"%@:%@",item.commentItem.user.username,item.commentItem.content];
textH = [totalStr sizeWithFont:[UIFont systemFontOfSize:] constrainedToSize:CGSizeMake(textW, MAXFLOAT)].height;
commentH = + textH;
}
CGFloat commentW = textW;
CGFloat commentX = margin;
CGFloat commentY = _cellH;
_commentViewFrame = CGRectMake(commentX, commentY, commentW, commentH);
_cellH = CGRectGetMaxY(_commentViewFrame) + margin;
}
处理数据原码
- (void)setItem:(XTThemeItem *)item
{
[super setItem:item]; [self setButton:_dingView count:item.ding title:@"赞"];
[self setButton:_caiView count:item.cai title:@"踩"];
[self setButton:_shareView count:item.repost title:@"转发"];
[self setButton:_commentView count:item.comment title:@"评论"];
} - (void)setButton:(UIButton *)button count:(NSInteger)count title:(NSString *)title
{
如何抽取一个方法:先把要抽取成方法的源代码拷贝过来,缺什么补什么就行了,需要外界决定的东西,写成参数,让外界传递进来
CGFloat valueF = ;
NSString *str = title;
if (count > 10000.0) {
valueF = count / 10000.0;
str = [NSString stringWithFormat:@"%.1f万",valueF];
str = [str stringByReplacingOccurrencesOfString:@".0" withString:@""];
} else if (count > ) {
str = [NSString stringWithFormat:@"%ld",count];
}
[button setTitle:str forState:UIControlStateNormal];
}
self.selectionStyle = UITableViewCellSelectionStyleNone;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
设置frame源代码
- (void)setFrame:(CGRect)frame
{
frame.origin.y += ;
frame.size.height -= ;
注意:一定要调用super方法
[super setFrame:frame];
}
设置cell背景图片原码
UIImage *image = [UIImage imageNamed:@"mainCellBackground"];
处理图片:设置可拉伸区域
image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5]; self.backgroundView = [[UIImageView alloc] initWithImage:image];
不等高cell搭建(二)的更多相关文章
- 不等高cell的tableView界面搭建
一.搭建界面 1.界面分析 分析界面的层次结构,分析界面应该用什么控件来搭建 2.界面层次结构 分析之后,我们可以把这个界面分为四个模块(topView middleView commentView ...
- iOS开发——UI进阶篇(三)自定义不等高cell,如何拿到cell的行高,自动计算cell高度,(有配图,无配图)微博案例
一.纯代码自定义不等高cell 废话不多说,直接来看下面这个例子先来看下微博的最终效果 首先创建一个继承UITableViewController的控制器@interface ViewControll ...
- 自定义不等高cell—storyBoard或xib自定义不等高cell
1.iOS8之后利用storyBoard或者xib自定义不等高cell: 对比自定义等高cell,需要几个额外的步骤(iOS8开始才支持) 添加子控件和contentView(cell的content ...
- 不等高cell的搭建(一)
一.界面搭建 1.确定开发模式 如果界面是固定的,可以用xib 界面的一些内容不固定,就用纯代码 cell用什么方式去开发(我们采用纯代码和xib结合的方式) 2 ...
- 纯代码自定义不等高cell
数据模型.plist解析这里就不过多赘述. 错误思路之一: 通过在heightForRowAtIndexPath:方法中调用cellForRowAtIndexPath:拿到cell,再拿到cell的子 ...
- iOS之处理不等高TableViewCell的几种方法
课题一:如何计算Cell高度 方案一:直接法(面向对象) 直接法,就是把数据布局到Cell上,然后拿到Cell最底部控件的MaxY值. 第一步:创建Cell并正确设置约束,使文字区域高度能够根据文字内 ...
- 处理不等高TableViewCell
课题一:如何计算Cell高度 方案一:直接法(面向对象) 想知道妹纸爱你有多深?直接去问妹纸本人吧! 嗯!Cell也是一样的,想知道cell到底有多高?直接问Cell本人就好了.直接法,就是把数据布局 ...
- iOS-UI控件之UITableView(二)- 自定义不等高的cell
不等高的cell 给模型增加frame数据 所有子控件的frame cell的高度 @interface XMGStatus : NSObject /**** 文字\图片数据 ****/ // ... ...
- iOS开发——UI进阶篇(二)自定义等高cell,xib自定义等高的cell,Autolayout布局子控件,团购案例
一.纯代码自定义等高cell 首先创建一个继承UITableViewCell的类@interface XMGTgCell : UITableViewCell在该类中依次做一下操作1.添加子控件 - ( ...
随机推荐
- caca393刷PTP教程
http://www.chickenclix.com/ 让大家等急了,最近真是很忙,对不住了:)好了闲话少说开始讲正题,再说可能有人要拍砖了............我们就以http://www ...
- XBox 开发者大会
今天参加了微软的Xbox开发者大会,虽然没我什么事情,不过还是有不少的收获,随便说说自己的一点感受吧. 先上几张图,附带妹子一个,不过手机不清楚哈,~~ 1 ID@XBOX开发者计划与独立游戏开发者 ...
- 线性表集合A=A B
大话数据结构 void union(List *a, List Lb) { int La_len, Lb_len, i; ElemType e; La_len = ListLength(La); Lb ...
- nodejs 执行shell 命令
有需要从前端操作服务器执行shell命令的需求 建立一个process.js文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var process = ...
- Array原型链添加“遍历”方法
<script> //1.在我们之前的项目里向原型链中集成方法时大多代码分析不严密,有时间我在这里会做详细分析; Array.prototype.each = function(fn) { ...
- Ajax如何实现跨域问题
一个域名的组成 http:// www . abc.com : 8080 /scripts/jquery.js 协议 子域名 主域名 端口号 请求资源地址 当协议.子域名.主域名.端口号中任意一个不同 ...
- [LeetCode]题解(python):039-Combination Sum
题目来源 https://leetcode.com/problems/combination-sum/ Given a set of candidate numbers (C) and a targe ...
- OC的内存管理
摘自:http://blog.csdn.net/hahahacff/article/details/39839571 OC内存管理 一.基本原理 (一)为什么要进行内存管理. 由于移动设备的内存极其有 ...
- 添加 Gradle 依赖与 build.gradle 配置初识
添加 Gradle 我们可以到我们添加 Maven 依赖的网站 Maven Repository: Search/Browse/Explore http://mvnrepository.com/ 上查 ...
- Jackson:fasterxml和codehaus的区别
Jackson fasterxml和codehaus的区别: 它们是jackson的两个分支.也是两个版本的不同包名.jackson从2.0开始改用新的包名fasterxml:1.x版本的包名是cod ...