简体   繁体   English

如何在UITableView中设置单元格高度?

[英]How to set cell height in UITableView?

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    let height = self.navigationController?.navigationBar.frame.size.height
    return view.frame.size.height - height!
}

I want to change the cell size — I use only one cell. 我想更改单元格大小-我只使用一个单元格。

My purpose is to fit the screen. 我的目的是适合屏幕。 However, in my case, the cell is scrolled. 但是,就我而言,该单元格已滚动。

I think it is necessary to calculate the safe area. 我认为有必要计算安全区域。 What if I do not have a smaller or larger screen? 如果我没有更大或更小的屏幕怎么办?

Please calculate like below for height, includes safe area code. 请按照以下方式计算高度,包括安全区号。

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    let height = view.bounds.height -  view.safeAreaInsets.top - view.safeAreaInsets.bottom
    return  height!
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM