Ios Swift-更改幻灯片大小以删除tableView中的按钮
是否有方法更改删除按钮的大小,以便在tableView中删除幻灯片?我为单元格创建了自己的边框,因此删除按钮延伸到边框中,如下所示: 相关代码如下:Ios Swift-更改幻灯片大小以删除tableView中的按钮,ios,swift,uitableview,swift4,Ios,Swift,Uitableview,Swift4,是否有方法更改删除按钮的大小,以便在tableView中删除幻灯片?我为单元格创建了自己的边框,因此删除按钮延伸到边框中,如下所示: 相关代码如下: func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let deleteAction = UICon
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
self.reminders.remove(at: indexPath.row)
tableView.reloadData()
}
deleteAction.backgroundColor = .red
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
return configuration
}
试试这个
最新答案
表视图单元格的高度
设置表格视图约束的高度:
heightOfTableViewConstraint = NSLayoutConstraint(item: self.tableView, attribute: .height, relatedBy: .equal, toItem: containerView, attribute: .height, multiplier: 0.0, constant: 1000)
containerView.addConstraint(heightOfTableViewConstraint)
UIView.animate(withDuration: 0, animations: {
self.tableView.layoutIfNeeded()
}) { (complete) in
var heightOfTableView: CGFloat = 0.0
// Get visible cells and sum up their heights
let cells = self.tableView.visibleCells
for cell in cells {
heightOfTableView += cell.frame.height
}
// Edit heightOfTableViewConstraint's constant to update height of table view
self.heightOfTableViewConstraint.constant = heightOfTableView
}
调用tableView.LayoutIfNeed(),完成后,查找可见单元格,汇总其高度,并编辑heightOfTableViewConstraint:
heightOfTableViewConstraint = NSLayoutConstraint(item: self.tableView, attribute: .height, relatedBy: .equal, toItem: containerView, attribute: .height, multiplier: 0.0, constant: 1000)
containerView.addConstraint(heightOfTableViewConstraint)
UIView.animate(withDuration: 0, animations: {
self.tableView.layoutIfNeeded()
}) { (complete) in
var heightOfTableView: CGFloat = 0.0
// Get visible cells and sum up their heights
let cells = self.tableView.visibleCells
for cell in cells {
heightOfTableView += cell.frame.height
}
// Edit heightOfTableViewConstraint's constant to update height of table view
self.heightOfTableViewConstraint.constant = heightOfTableView
}
有没有办法得到每个单元格的高度?我使用UITableViewAutomaticDimension表示行高,因此每个单元格都略有不同。您能解释一下子视图的用途吗?我不确定我是否完全理解你的代码。请看这个