不等高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.添加子控件 - ( ...
随机推荐
- HTML Questions:Front-end Developer Interview Questions
What's a doctype do? Instruct the browser to render the page. What's the difference between standard ...
- SQL查询(一)
查询基础练习 练习一: <学生信息表>:students(学号,姓名,性别,出生年,省份,入学年份,班级) <学生选修信息表>:stucourses(学号,课程号,课程名称,分 ...
- 正则基础之 \b 单词边界
本文转载自: http://www.jb51.net/article/19330.htm 1概述 “\b”匹配单词边界,不匹配任何字符. “\b”匹配的只是一个位置,这个位置的一侧是构成单词的字符,另 ...
- c/c++编译时,指定程序运行时查找的动态链接库路径
http://blog.csdn.net/tsxw24/article/details/10220735 c/c++编译时,指定程序运行时查找的动态链接库路径 分类: c/c++ linux 2013 ...
- C语言PRO2
2-5 #include<stdio.h>#include<math.h>int main(){ int money , year; double rate , sum; pr ...
- 关于Bitcode的探索
Bitcode概述 Bitcode is an intermediate representation of a compiled program. Apps you upload t ...
- Cocos2d-JS cc.DrawNode用法
app.js var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function () { ///////////////////// ...
- MAC下配置ZSH
Mac的Terminal出了bash还配备了zsh模式,相比于bash,zsh的界面更加简单精致,用户名直接省略,用一个小箭头代替,而且箭头的颜色还可以指示命令的对错:路径和文件名的自动补全功能也十分 ...
- How to disable and clear query ranges in sysquery form
query = new query('Query name'); queryBuildDataSource = query.dataSourceTable(tableNum('table name') ...
- E1114 Temp Ambient
这2天DELL服务器的指示灯变为了黄色 ,显示“ E1114 Ambient Temp exceeds allowed range“ 原来是周围环境温度超出了许可范围 ,难道最近的天真的是太冷了 ”