How to make a custom edit view in iOS7 UITableView with Objective C like the Evernote or the Apple Reminders app while swipe left. I have tried to set an custom editingAccessoryView, but this didn't work.
Evernote edit view:
Reminders edit view:
My current code is
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSLog(@"delete");
}
}
I have tried to solve the problem with: (UITableViewController.h)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//make cell
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[view setBackgroundColor:[UIColor greenColor]];
//add Buttons to view
cell.editingAccessoryView = view;
return cell;
}
And the same with: (UITableViewCell)
- (void)willTransitionToState:(UITableViewCellStateMask)state;
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
- (UIView*)editingAccessoryView;
Refer this link : https://github.com/TeehanLax/UITableViewCell-Swipe-for-Options
And customize your uitableviewcell with multiple button.
I have implemented this code with my app got such result. You can add number of button in swipe cell.
Here is implemented screen shots
After swipe the cell 3 buttons appears "More","Share","Delete".
You can use
UITableViewRowAction
'sbackgroundColor
to set custom image or view. The trick is usingUIColor(patternImage:)
.Basically the width of
UITableViewRowAction
area is decided by its title, so you can find a exact length of title(or whitespace) and set the exact size of image withpatternImage
.To implement this, I made a
UIView
's extension method.and to make a string with whitespace and exact length,
and now, you can create
UITableViewRowAction
.The result will look like this.
Another way to do this is to import custom font which has the image you want to use as a font and use
UIButton.appearance
. However this will affect other buttons unless you manually set other button's font.From iOS 11, it will show this message
[TableView] Setting a pattern color as backgroundColor of UITableViewRowAction is no longer supported.
. Currently it is still working, but it wouldn't work in the future update.As I think, It's not best way to using UIGestureRecognizer-based cells.
First, you'll not have any options to use CoreGraphics.
Perfect solution, will UIResponder or one
UIGestureRecognizer
for whole table view. Not for everyUITableViewCell
. It will make you app stuck.If you want to use only text while making swipe actions then you can use iOS default swipe actions but if you want image and text, then you have to customize it. I have found a great tutorial and sample that can resolve this problem.
Try out this repository to get the custom swipe cell. You can add multiple option here.
http://iosbucket.blogspot.in/2016/04/custom-swipe-table-view-cell_16.html
https://github.com/pradeep7may/PKSwipeTableViewCell
Swift 3
Swift 2.1
Note: for iOS 8 onwards
The above code shows how to create to custom buttons when your swipe on the row.