Snpkit自适应高度布局在这里
lazy var tableview: UITableView = {
let t = UITableView(frame: .zero, style: .plain)
t.dataSource = self
t.delegate = self
t.separatorStyle = .none
t.rowHeight = UITableView.automaticDimension //核心代码
t.estimatedRowHeight = 100 //核心代码
t.backgroundColor = .jk_FDFDFD()
// t.register(JKReportHeaderCell.self, forCellReuseIdentifier: "JKReportHeaderCell")
// t.register(JKReportCell.self, forCellReuseIdentifier: "JKReportCell")
t.contentInsetAdjustmentBehavior = .never
return t
}()
指定某一个cell固定高度在这里
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
return CXScreenBase375(276 + 8) // 核心代码
}
return UITableView.automaticDimension
}
回答标题所述Snpkit 布局cell自适应高度但有最小高度限制怎么搞?
首先使用自适应布局,cell的contentView重头连接到尾(我这叫它连接1线);
其次在有这样要求的cell中判断cell的contentView高度是否小于最小要求高度值,如果小于就新增个连接2线来更改cell拉伸,判断代码如下
核心代码
let contentHeight = contentView.systemLayoutSizeFitting(CGSize(width: CXScreenWidth(), height: UIView.layoutFittingCompressedSize.height)).height
if contentHeight < cell高度 {
//使用这个撑起来,之前使用连接1撑起的,这个在布局中之前没有连bottom
resourceImageview.snp.remakeConstraints { make in
make.top.equalTo(12)
make.right.equalTo(-12)
make.size.equalTo(72)
make.bottom.equalTo(-12)
}
}
网友评论