我试图在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])
}

图像,我使用的是

发布于 2018-06-05 05:56:21
我们可以取30乘30,是标准尺寸,我们可以取30像素以上,这取决于屏幕的大小.
下面是支持的图像

发布于 2019-02-22 13:57:54
UIContextualAction只接受模板图像,使用不同的透明度来定义图像的形状和颜色。
发布于 2020-12-15 07:36:45
嗨,对我来说很好,
该图像大小将根据图像的像素自动调整。
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
}https://stackoverflow.com/questions/50677458
复制相似问题