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
}
WWDC video at 28.34
Apple Doc
Note: I have used 50*50 points apple.png image with 50 tableview
row height
Related Topics
How to Find the Kind of Errors a Method May Throw and Catch Them in Swift
Ios7 - Device Unique Identifier
How to Find Out What View a Touch Event Ended At
Pinch to Zoom Effect on Uiimageview Inside Scrollview
How to Start an Ibeacon Transmitter in the Background
Restore Button for iOS Non-Consumable In-App Purchase
Dismiss a Parent Modal in Swiftui from a Navigationview
Building Ffmpeg iOS Libraries for Armv7, Armv7S, Arm64, I386 and Universal
How to Make a Mkannotationview Touch Sensitive
Gssendevent - Inject Touch Event iOS
Conditionally Hide Code from the Compiler
Get Cellid, Mcc, Mnc, Lac, Signal Strength, Quality and Network in iOS 8.3
Uisearchbar's Cancel and Clear Buttons Not Working in iOS 7
Not Getting the Email Using Google Authentication in Firebase