UITableView-FDTemplateLayoutCell 与Masonry 一起解决不定高度的cell
来源:互联网 发布:淘宝联盟pc客户端 编辑:程序博客网 时间:2024/05/08 05:35
控制器
//// ViewController.m// shiyan//// Created by aimee on 16/9/28.// Copyright © 2016年 aimee. All rights reserved.//#import "ViewController.h"#import <UITableView+FDTemplateLayoutCell.h>#import <Masonry.h>#import "TableViewCell.h"#import "Model.h"@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>{ Model *model;}/** <#属性名#> */@property (nonatomic, strong)UITableView *tableView;@endstatic NSString * cellID = @"cellID";@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; self.tableView.backgroundColor = [UIColor redColor]; [self.view addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.and.bottom.and.left.and.right.mas_equalTo(0); }]; [self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:cellID]; self.tableView.delegate = self; self.tableView.dataSource = self; model = [Model new]; model.name = @"fhaiosefijafgefeawgefagasgsaaf我飞偶哇和规范iOSA货给哦撒谎个撒谎个"; model.text = @"fesajigejsapgjepa]jgpirasjgoprajgopsagjeowagjosajgeosa]jgeposajgeopasjgepsajgopsajgeopsajgefeawgfeageawgfresagrasgraerasgra";}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 2;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; cell.model = model; return cell;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return [self.tableView fd_heightForCellWithIdentifier:cellID cacheByIndexPath:indexPath configuration:^(TableViewCell *cell) { cell.model = model; }];}@end
模型
//// Model.h// shiyan//// Created by aimee on 16/9/29.// Copyright © 2016年 aimee. All rights reserved.//#import <Foundation/Foundation.h>@interface Model : NSObject/** name */@property (nonatomic, copy) NSString *name;@property (nonatomic, copy) NSString *text;@property (nonatomic, copy) NSString *des;@property (nonatomic, copy) NSString *time;@end
cell
//// TableViewCell.m// shiyan//// Created by aimee on 16/9/29.// Copyright © 2016年 aimee. All rights reserved.//#import "TableViewCell.h"#import <Masonry.h>#import "Model.h"@interface TableViewCell()/** <#属性名#> */@property (nonatomic, strong)UIView *whiteView;/** <#属性名#> */@property (nonatomic, strong)UILabel *name_L;@property (nonatomic, strong)UILabel *text_L;@end@implementation TableViewCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self creatSubviews]; } return self;}- (void)creatSubviews{ self.whiteView = [[UIView alloc] init]; self.whiteView.backgroundColor = [UIColor yellowColor]; [self.contentView addSubview:self.whiteView]; [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(0);#pragma mark - 关键1这个约束一定要有 make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-10); }]; self.text_L = [[UILabel alloc] init]; [self.whiteView addSubview:self.text_L]; self.text_L.numberOfLines = 0; self.text_L.font = [UIFont systemFontOfSize:20]; [self.text_L mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.mas_equalTo(10); make.height.greaterThanOrEqualTo(@40); }]; self.name_L = [[UILabel alloc] init]; [self.whiteView addSubview:self.name_L]; self.name_L.numberOfLines = 0; self.name_L.font = [UIFont systemFontOfSize:20]; [self.name_L mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.text_L.mas_left); make.top.mas_equalTo(self.text_L.mas_bottom).offset(50); make.right.mas_equalTo(self.text_L.mas_right);#pragma mark - 关键2这个约束一定要有 make.bottom.mas_equalTo(self.whiteView.mas_bottom).offset(-10); }];}- (void)setModel:(Model *)model{ _model = model; self.text_L.text = model.text; self.name_L.text = model.name;}@end
0 0
- UITableView-FDTemplateLayoutCell 与Masonry 一起解决不定高度的cell
- cell自动计算高度(masonry与UITableView-FDTemplateLayoutCell)
- Masonry 和 UITableView-FDTemplateLayoutCell 实现自适应高度的Cell
- 使用UITableView+FDTemplateLayoutCell计算cell的高度
- UITableView-FDTemplateLayoutCell缓存cell高度时,cell重叠高度为0的问题解决
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
- Masonry和UITableView-FDTemplateLayoutCell的结合使用
- 缓存cell高度开源代码阅读:UITableView-FDTemplateLayoutCell
- iOS UITableView-FDTemplateLayoutCell框架 cell重叠 高度返回0.5问题解决
- UITableView性能优化---自动计算cell高度(FDTemplateLayoutCell)
- Masonry和FDTemplateLayoutCell搭配使用「UITableview自适应内容高度」
- 【iOS】Masonry和FDTemplateLayoutCell搭配使用「UITableview自适应内容高度」
- Masonry+FDTemplateLayoutCell 实现Cell自动布局
- UITableView-FDTemplateLayoutCell----UITableViewCell高度计算的那些事
- UITableView的cell自适应高度
- UITableView的cell自适应高度
- 基于Masonry自动计算cell的高度
- build gradle project info很久
- Mongodb启动命令mongod参数说明
- 需求调研
- mysql优化存储过程中批量插入的速度
- svn使用手册
- UITableView-FDTemplateLayoutCell 与Masonry 一起解决不定高度的cell
- Redis搭建(三)
- RXjava基本操作符
- 大型网站技术架构(二):架构体系的技术介绍
- Material和Shader是什么,两者有什么关系?
- 算法导论2.2-2selection-sort(选择排序)
- c++中Cstring和int相互转换
- wchar_t123
- 使用Ubuntu虚拟机下的hgfs文件夹和Windows主机共享