UI_UItableView_AutoCell(自定义cell 高度)

来源:互联网 发布:js中name选择器 编辑:程序博客网 时间:2024/06/14 19:28
#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]];}


0 0
原创粉丝点击