I use the following trick in order to have images in table view row actions:
How to manage equal width for UITableViewRowAction in iOS8.0?(More,Delete,etc actions)
UITableViewRowAction *completeAction = [UITableViewRowAction
rowActionWithStyle:UITableViewRowActionStyleNormal
title:@" "
handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
...
}];
completeAction.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"MyImageHere"]];
but it no longer works with iOS 11 - the width of the row action button is too big for my image so it's repeated:
Is there a fix for this?
Update:
I ended up using the new trailing / leading contextual actions API introduced in iOS 11:
https://developer.apple.com/documentation/uikit/uicontextualaction
This API allows you to have images in actions and more.
#if defined __IPHONE_11_0 && __has_builtin(__builtin_available)
// This will be called on iOS 11+ if compiling with Xcode 9.
- (id)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
if (@available(iOS 11.0, *)) {
UISwipeActionsConfiguration *configuration = ...
return configuration;
}
return nil;
}
#endif
// This will be called on iOS 10 and older.
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
// Old style row actions.
}
Be aware that if you compile code like this with Xcode 8 the new delegate method will not be defined (and you will see the bug).