【问题标题】:Swift - How to vertically transform (flip) a custom UITableViewRowActionSwift - 如何垂直转换(翻转)自定义 UITableViewRowAction
【发布时间】:2021-01-11 20:00:08
【问题描述】:

我正在尝试在我的表格视图中实现滑动以删除行操作,但出于设计目的,表格视图使用tableView.transform = CGAffineTransform(scaleX: 1, y: -1) 倒置,所以我的大红色删除按钮是倒置的。有没有简单的方法可以在上面使用cell.contentView.transform = CGAffineTransform(scaleX: 1, y: -1)

我尝试使用以下方法进行自己的滑动操作

func tableView(_ tableView: UITableView,
                 editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .default,
                                      title: "Delete",
                                      handler: { (_: UITableViewRowAction, _: IndexPath) -> Void in

      })
    //Flip the text here
    return [delete]
  }

但我看到的只是背景颜色和效果。

有什么帮助吗? :) 非常感谢,谢谢!

【问题讨论】:

    标签: swift uitableview uikit tableview transform


    【解决方案1】:

    您可以手动翻转您要使用的图像并像这样分配它吗?

    let deleteAction = UIContextualAction(style: .destructive, title: nil) { (_, _, completionHandler) in
        self.viewModel.deleteScan(at: indexPath.row)
        completionHandler(true)
    }
    
    deleteAction.image = UIImage(named: "upside-down-delete")
    deleteAction.backgroundColor = UIColor(named: "Red800-Red500")
    

    【讨论】:

    • 感谢您的帮助!我现在唯一遇到的问题是在函数中返回它,因为它需要一个 [UITableViewRowAction] 数组,还是您的意思是在该函数之外的某个地方使用它?
    • 我设法让它工作,但只能使用 func tableView(_ tableView: UITableView,leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {} 不幸的是我想要的另一面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-25
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    相关资源
    最近更新 更多