Image in Tableviewcell Swipe Action

Image in TableViewCell swipe action

In the second image, the green is the UIContextualAction's backgroundColor and the white is the tintColor.

The image is treated as a template image — that is, its colors are ignored, and instead it is drawn transparent where your image is transparent, and drawn opaque with the tintColor where your image is opaque.

So, basically you would need to reverse your settings: set the background color to white and change the tint color to the darker green shown in your image. Setting the tint color is not easy, but you could do it, for example, in your app delegate didFinishLaunching using the appearance proxy, as suggested here (though this may have other unwanted side effects):

UIImageView.appearance(
whenContainedInInstancesOf: [UITableView.self])
.tintColor = // whatever that green is

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

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)

How to add swipe actions for table view cell in swift 5

Try the following method:

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let item = UIContextualAction(style: .destructive, title: "Delete") { (contextualAction, view, boolValue) in
//Write your code in here
}
item.image = UIImage(named: "deleteIcon")

let swipeActions = UISwipeActionsConfiguration(actions: [item])

return swipeActions
}

How to add image in UITableViewRowAction?

Finally in iOS 11, SWIFT 4 We can add add image in UITableView's swipe action with help of UISwipeActionsConfiguration

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

let action = UIContextualAction(style: .normal, title: "Files", handler: { (action,view,completionHandler ) in
//do stuff
completionHandler(true)
})
action.image = UIImage(named: "apple.png")
action.backgroundColor = .red
let configuration = UISwipeActionsConfiguration(actions: [action])

return configuration
}

Sample Image

WWDC video at 28.34

Apple Doc

Note: I have used 50*50 points apple.png image with 50 tableview row height



Related Topics



Leave a reply



Submit