UIContextualAction在Swift中具有图标和清晰背景

5tmbdcev  于 2023-08-02  发布在  Swift
关注(0)|答案(2)|浏览(123)

我使用以下代码

let deleteAction =
   UIContextualAction(style: .normal, title: ""){ (action, sourceView, completionHandler) in

            self.dataManager.items.remove(at: indexPath.row)
            self.itemCardTableView.deleteRows(at: [indexPath], with: .automatic)
            completionHandler(true)
    }

let deleteResize = #imageLiteral(resourceName: "delete72").resizeImage(withSize: CGSize(width: 50, height: 50), scaleMode: .contentAspectFill)
    deleteAction.backgroundColor = UIColor.white
    deleteAction.backgroundColor = UIColor(patternImage: deleteResize!)

字符串
图像被重复。这不是我想要的
https://i.stack.imgur.com/xUUWY.png
我想要的是这样的
https://i.stack.imgur.com/CV5DX.png
怎么修

44u64gxh

44u64gxh1#

不要使用UIColor(patternImage: deleteResize!),而是使用UIContextualAction示例的image属性。
要得到一个真正的.clear背景已经在这里解决了https://stackoverflow.com/a/51939297/5058116,但显得很凌乱...

kb5ga3dv

kb5ga3dv2#

你能用**alpha = 0.**设置背景色吗?

let deleteAction = UIContextualAction(style: .normal, title:  "Delete", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
                  //TODO: 
        })
      deleteAction.backgroundColor = .white.withAlphaComponent(0)

字符串

相关问题