UI_UItableView_AutoCell(自定义cell 高度)
2015-07-14 20:31
357 查看
#pragma mark 赋值方法 -(void)setCellDataWithModel:(NewsModel *)sender { self.titleLabel.text = sender.title; self.summaryLabel.text = sender.summary; CGFloat height = [NewsCell getHeightWithModel:sender]; // 把计算出来的高度赋值给label CGRect labelFrame = self.summaryLabel.frame; labelFrame.size.height = height; self.summaryLabel.frame = labelFrame; }
#pragma mark - 计算高度的方法 + (CGFloat)getHeightWithModel:(NewsModel *)model { // 计算高度 (summaryLabel) // 宽度,高度必须定死一个 NSDictionary *fontDic = @{NSFontAttributeName:[UIFont systemFontOfSize:17.0f]}; CGRect rectFrame = [model.summary boundingRectWithSize:(CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, MAXFLOAT)) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:fontDic context:nil]; return rectFrame.size.height; }
#pragma mark - 计算 cell 高度 + (CGFloat)heightWithModel:(NewsModel *)model { // 当做标记 opeModel = model; return [self getHeightWithModel:model] + 20 + 25; }
// 封装 + (instancetype)getCinemaCellWithTableView:(UITableView *)tableView { static NSString *cell_id = @"CinemaCell"; CinemaCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id]; // if (cell == nil) { // cell = [[CinemaCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cell_id]; // } return cell; }
#pragma mark - cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row < 10) { CinemaCell *cell = [CinemaCell getCinemaCellWithTableView:tableView]; // 设置cell 的值 [cell setCellDateWithModal:self.dataArray[indexPath.row]]; return cell; } else { static NSString *cell_id1 = @"UITableViewCell"; CinemaCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id1]; cell.textLabel.text = @"llldsoie"; return cell; } }
#pragma mark - cell 高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [NewsCell heightWithModel:self.dataArray[indexPath.row]]; }
相关文章推荐
- UI中一些名词的缩写
- 暑假选拔赛02 ---- Ysequence
- The method setPositiveButton(int, DialogInterface.OnClickListener) in the type AlertDialog.Builder i
- UI基础(一)
- String, StringBuilder , StringBuffer
- NGUI UIWrapContent小用法
- UITableView简单性能优化
- @DynamicUpdate(true) @DynamicInsert(true)使用的环境
- 算法导论 第七章:快速排序(Quicksort)
- Leetcode-N-Queens II
- Leetcode-N-Queens
- [LintCode] N-Queens
- 你用什么方法检查 PHP 脚本的执行效率(通常是脚本执行时间)和数据库 SQL 的效率(通常是数据库 Query 时间), 并定位和分析脚本执行和数据库查询的瓶颈所在?
- iOS发展系列II - UILabel 使用摘要
- 【设计和开发一套简单自动化UI框架】
- emulator: ERROR: x86 emulation currently requires hardware acceleration!Please ensure Intel HAXM is
- 代码手写UI,xib和StoryBoard间的博弈,以及Interface Builder的一些小技巧
- iOS修改UIButton setTitle字体颜色和调整字体位置
- request.getScheme()
- 快速排序(Quicksort)