I would like to edit the UITableViewRowAction of my table. My cells have rounded edges and a border, I would like to edit the style of the RowAction to match the style of my cells.
I understand that currently only backgroundColor, title and style (default, destructive, normal...) can be changed (link). However, I feel that this is a little bit too restricted? Perhaps I could subclass UITableViewRowAction to create my own look and feel? Any advice would be appreciated.
Unfortunately I can't post an example image because I don't have 10 rep yet (haha). However I think the question is simple enough to be understood without a visual representation.
As you said the only things you can change on the action are:
In order to change the style of the UITableViewRowAction is the probable solution is adding the image using 'patternimage'.
Here is the solution for this.And I am not saying this is the exact solution, because as now we not have access to all the properties of the 'UITableViewRowAction'
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"test" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// show UIActionSheet
}];
float wwidth =[moreAction.title sizeWithAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:15.0]}].width;
wwidth = wwidth+<55 change this value for exact width>;
moreAction.backgroundColor = [[UIColor alloc] initWithPatternImage:[self imageWithImage:[UIImage imageNamed:@"temp.jpg"] scaledToSize:CGSizeMake(wwidth, tableView.rowHeight)]];
UITableViewRowAction *flagAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Flag" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// flag the row
}];
flagAction.backgroundColor = [UIColor yellowColor];
return @[moreAction, flagAction];
}
Note: use the High resolution image so that it works for
iPhone 6 Plus 736x414 points 5.5"
iPhone 6 667x375 points 4.7"
iPhone 5 568x320 points 4.0"
iPhone 4 480x320 points 3.5"
Useful post on this link http://pablin.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With