1

I use the following code

  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!)

image is repeated. This is not what I want

https://i.stack.imgur.com/xUUWY.png

I want is like this

https://i.stack.imgur.com/CV5DX.png

How to fix it

Josh
  • 43
  • 1
  • 1
  • 8

2 Answers2

0

Do not use UIColor(patternImage: deleteResize!), instead use the image property of the UIContextualAction instance.

To get a truly .clear background has been solved here https://stackoverflow.com/a/51939297/5058116, but appears very messy ...

ajrlewis
  • 2,968
  • 3
  • 33
  • 67
0

Can you set background color with alpha = 0.

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