use*_*622 9 uitableview custom-cell swift
你能告诉我,在UITableview上滑动单元格时如何添加自定义图像来删除按钮?
搜索您需要的功能"editActionsForRowAtIndexPath",您可以在其中创建操作范围.您需要将UIImage设置为UITableViewRowAction的backgroundColor.
let someAction = UITableViewRowAction(style: .Default, title: "") { value in
println("button did tapped!")
}
someAction.backgroundColor = UIColor(patternImage: UIImage(named: "myImage")!)
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以使用这个 UITableView 委托函数:
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = UIContextualAction(style: .normal, title: "", handler: {a,b,c in
// example of your delete function
self.YourArray.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .automatic)
})
deleteAction.image = UIImage(named: "trash.png")
deleteAction.backgroundColor = .red
return UISwipeActionsConfiguration(actions: [deleteAction])
}
Run Code Online (Sandbox Code Playgroud)
PS:我个人认为图标大小32是最好的
| 归档时间: |
|
| 查看次数: |
6363 次 |
| 最近记录: |