Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set clear background in table view cell swipe action?

I have a trailingSwipeAction in a UITableViewCell, whose background color must be clear.

This is the code where I set the action :

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let myAction = UIContextualAction.init(style: .normal, title: nil) {
        // My action code
    }
    myAction.backgroundColor = .clear
    myAction.image = UIImage.init(named: "my-icon")
    return UISwipeActionsConfiguration.init(actions: [myAction])
}

But I am getting gray background for the action, when no color was expected:

enter image description here

like image 505
Sergio Avatar asked Aug 20 '18 19:08

Sergio


1 Answers

You can just set the alpha value to 0 for background color of the action:

let modifyAction = UIContextualAction(style: .normal, title:  "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
    print("Update action ...")
    success(true)
})
modifyAction.backgroundColor = UIColor.init(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.0)
like image 139
Shubham Goel Avatar answered Sep 28 '22 03:09

Shubham Goel