OGeek|极客世界-中国程序员成长平台

标题: ios - 与 iOS 10+ 类似设计的滑动删除 UITableViewCell 中的通知滑动删除 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:18
标题: ios - 与 iOS 10+ 类似设计的滑动删除 UITableViewCell 中的通知滑动删除

如何使要删除的 tableviewcell 幻灯片看起来像要删除 iOS 通知的幻灯片(淡入并且不要触摸屏幕边缘)。我将只有删除按钮,所以我不需要多个按钮。我希望它像通知一样在完全滑动时删除。

这是一张带有 2 个按钮的想要结果的照片(我只想要 1 个):

iOS notification swipe to delete

我写的当前代码只是将编辑样式设置为删除。我曾尝试使用 UIContextualAction 但我相信我只能设置样式、背景颜色和/或图像。

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        print("delete")
    }
}

这是我当前代码的样子:What I currently have



Best Answer-推荐答案


尝试在 UITableViewCell 内添加一个 UIView,带有红色背景,并在 UIView 内添加一个带有删除文本的标签。祝你好运!

关于ios - 与 iOS 10+ 类似设计的滑动删除 UITableViewCell 中的通知滑动删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51120827/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4