不等高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.添加子控件 - ( ...
随机推荐
- Yii源码阅读笔记(十三)
Model类,集中整个应用的数据和业务逻辑: namespace yii\base; use Yii; use ArrayAccess; use ArrayObject; use ArrayItera ...
- MVC validation
<div class="editor-field"> @Html.TextBoxFor(m => m.DateField) @Html.ValidationMes ...
- Behavior-Based Intelligence
Computer Science An Overview _J. Glenn Brookshear _11th Edition Early work in artificial intelligenc ...
- php配置相关
php.ini error_reporting //配置错误的显示方式 display_errors //此项优先级高于error_reporting,如果关闭该项,会返还http状态码,如果开启,则 ...
- 最有用的Linux命令行使用技巧集锦
最近在Quora上看到一个问答题目,关于在高效率Linux用户节省时间Tips.将该题目的回答进行学习总结,加上自己的一些经验,记录如下,方便自己和大家参考. 下面介绍的都是一些命令行工具,这些工具在 ...
- Activity初步,初学者必看
Activity是什么? Activity是一个可与用户交互并呈现组件的视图.通俗说就是运行的程序当前的这个显示界面. 如果你还不明白,那么你写过HTML吗,它就好比一个网页.我们程序中的用户视图,都 ...
- Qt Model/View(官方翻译,图文并茂)
http://doc.trolltech.com/main-snapshot/model-view-programming.html 介绍 Qt 4推出了一组新的item view类,它们使用mode ...
- 利用堆排序找出数组中前n大的元素
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <time.h> ...
- eclipse根据.wsdl文件自动生成webservice的调用客户端
1.工具:eclipse3.3或者是带有webservice插件的eclipse 2. 首先用浏览器访问webservice的站点,接着保存打开的页面,后缀为.wsdl. 3.把保存好的文件拷入ecl ...
- 转:ASP.NET MVC利用TryUpdateModel来做资料更新 (一)
前言有使用 ASP.NET MVC 的朋友们一定多多少少有听过 TryUpdateModel,之前就看了很多有关它的文章,但在专案实务上都未曾实际使用过,而 TryUpdateModel 不仅能利用 ...