我在 Storyboard 中构建的 UITableView
中有三个单元格,当我运行它时,我在模拟器中得到了三个预期的单元格,然后是下面的空白区域。我想要做的是让单元格根据 iOS 设备动态填满屏幕。我该怎么做?
最佳答案
为单元格设置一个最小高度,如果项目很少,则使用偶数高度,否则使用minHeight。
let MinHeight: CGFloat = 100.0
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let tHeight = tableView.bounds.height
let temp = tHeight/CGFloat(items.count)
return temp > MinHeight ? temp : MinHeight
}
Swift 5 更新:
let minRowHeight: CGFloat = 100.0
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let tHeight = tableView.frame.height
let temp = tHeight / CGFloat(items.count)
return temp > minRowHeight ? temp : minRowHeight
}
关于ios - 使表格 View 单元格在 Swift 中完全填满屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35994977/