Ios 如何在UITableview数据源方法的UIContextualAction中添加图像

Ios 如何在UITableview数据源方法的UIContextualAction中添加图像,ios,swift,uitableview,Ios,Swift,Uitableview,我试图在UIContextualAction中添加图像,请参见下面的代码:- func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { // Write action code for the Flag let FlagActio

我试图在UIContextualAction中添加图像,请参见下面的代码:-

func tableView(_ tableView: UITableView,
               trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
   // Write action code for the Flag
    let FlagAction = UIContextualAction(style: .normal, title:  "View", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        print("Update action ...")
        success(true)
    })
    FlagAction.image =  UIImage(named: "flag")
    return UISwipeActionsConfiguration(actions: [FlagAction])
}

我正在使用的图像


我们可以选择30×30的尺寸,这是标准尺寸,我们可以选择30个以上的像素,这取决于屏幕的大小。

这是支持的图像


UIContextualAction只接受模板图像,它使用不同的透明度来定义图像的形状和颜色。

嗨,它对我来说很好

该图像大小将根据图像的像素自动调整

  private func searchBarCode(forRowAt indexPath: IndexPath) -> UIContextualAction {
    
    let context = UIContextualAction(style: .destructive, title: "") { (action, swipeButtonView, completion) in
        completion(true)
    }
    context.backgroundColor = UIColor.white
    context.image = UIImage(named: "document")
    
    return context
    }

检查您的图像大小,或者您从资产或其他渠道获取图像的位置尺寸:32*32缩小尺寸并检查我的朋友,我会尽一切可能缩小图像的尺寸。同样的问题也发生了。你能更新代码吗