TrailingSwipeActionsConfigurationForRowAt 中的图像似乎不起作用

Sja*_*ien 5 ios uiswipeactionsconfiguration

我正在尝试实现一项新的 iOS11 功能,该功能允许您在桌面视图滑动操作中正式使用图像。

所以,我想出了这个:

@available(iOS 11.0, *)
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let deleteAction = UIContextualAction(style: .normal, title:  "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
            //whatever
            success(true)
        })
        let theImage: UIImage? = UIImage(named:"Delete")?.withRenderingMode(.alwaysOriginal)

        deleteAction.image = theImage
        return UISwipeActionsConfiguration(actions: [deleteAction])
    }
Run Code Online (Sandbox Code Playgroud)

我的资产目录中有这个 .png 。我尝试了使用和不使用渲染模式。无论哪种情况,图像都会正确显示在调试器中:在此输入图像描述

但未能在模拟器中显示(“这里什么都没有”标记了我期望图像显示的位置): 在此输入图像描述

难道我做错了什么?

小智 0

我有同样的问题,几天来一直在尝试解决这个问题。尚未在任何地方找到解决方案。

不过,一种已弃用的解决方法是将构造为patternImage的backgroundColor设置为如下所示:

let deleteAction = UIContextualAction(style: .normal, title:  "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        //whatever
        success(true)
    })
let theImage: UIImage? = UIImage(named:"Delete")
deleteAction.backgroundColor = UIColor(patternImage: theImage!)
Run Code Online (Sandbox Code Playgroud)