UITableViewRowAction custom style?

I would like to edit UITableViewRowAction

my spreadsheet. My cells have rounded edges and a border, I would like to edit the style 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 like this is a little limited? 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 (haha) yet. However, I think this question is simple enough to be understood without visual representation.

+3


source to share


2 answers


As you said, the only thing you can change in action is:

  • BackgroundColor
  • style (destructive (red background color, ...)
  • name

To change the style of the UITableViewRowAction, the likely solution is to add an image using a template.

Here is a solution for that. And I am not saying that this is an exact solution, since now we do 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 a high resolution image to make it work 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"

      

Helpful post at this link http://pablin.org/

+7


source


You can try: Custom UITableViewCell Custom UITableViewCell that supports the cell drag gesture to open a custom menu of buttons or other views. It supports:



  • fully customizable UIView for use as canvas for custom buttons and views;
  • Automatic layout;
  • storyboards;
  • easy reuse of elements;
  • highlight / highlight cells;
  • selection / deselection of cells;
  • normal and edit mode;
  • accessory types;
  • compatible with iOS 7 and 8.
0


source







All Articles