开发小技巧

Cell高度自适应

2017-06-06  本文已影响43人  MrSong

Cell高度自适应

@(iOS)[UITableView]

这是找到的最简单一种自适应方法了,代码量不多

- (void)setCheckModel:(MMKeyPlacesVisitAgainCheckAreaModel *)checkModel {
    _checkModel = checkModel;
    self.titleLable.text = checkModel.name;
    CGSize size = [self sizeString:checkModel.name WithFont:[UIFont systemFontOfSize:FontSize] constrainedToSize:CGSizeMake(ScreenWidth, MAXFLOAT)];
    self.titleLable.frame = CGRectMake(0, 0, ScreenWidth, size.height >= 40 ?:40);
    self.yesLable.frame = CGRectMake(0, _titleLable.SLQBottom, 20, 40);
    self.yesBtn.frame = CGRectMake(_yesLable.SLQRight , _titleLable.SLQBottom, 40, 40);
    self.noLable.frame = CGRectMake(_yesBtn.SLQRight , _titleLable.SLQBottom, 20, 40);
    self.noBtn.frame = CGRectMake(_noLable.SLQRight, _titleLable.SLQBottom, 40, 40);
    self.SLQHeight  = self.noBtn.SLQBottom;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
上一篇下一篇

猜你喜欢

热点阅读