3

I implemented a tableview with custom cells. The cells have their cornerRadius set to 2. Everything displays just fine until I enter edit mode. When the delete button appears, it's corner radius is 0.

How can I make the delete button have a cornerRadius too?

I tried this without any luck:

func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath)
    cell!.editingAccessoryView?.layer.cornerRadius = 2
}

enter image description here

The corner Radius is currently set as a User Defined Runtime Attribute in my Storyboard.

enter image description here

MikeB
  • 1,619
  • 2
  • 15
  • 27

1 Answers1

0

you can manipulate the button like this:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
  var button1 = UITableViewRowAction(style: .Default, title: "Delete", handler: { (action, indexPath) in
                  println("button1 pressed!")
              })


  UIGraphicsBeginImageContext(button1.view.frame.size);
  [[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();

  button1.view.backgroundColor = [UIColor colorWithPatternImage:image];

  return [button1]
}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
  return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
Mika
  • 5,807
  • 6
  • 38
  • 83
  • Value of type 'UITableViewRowAction' has no member 'layer' - Does not work... Couldn't find a way to get the buttons View either – MikeB Feb 16 '16 at 21:13
  • Ha... turns out the UITableViewRowAction does not inherit from UIButton... my bad... You have to use the backgroundColor property in that case. I will add some more code. – Mika Feb 16 '16 at 21:19
  • Edit done... I am on mobile so I can't test but it should be close. – Mika Feb 16 '16 at 21:23
  • Really appreciate the help! Great idea with the backGroundColor! Unfortunately UITableViewRowAction does not have a view property either. The only properties it does have are style, title, backgroundColor, backgroundEffect. None of those can be used to get the size... – MikeB Feb 16 '16 at 21:32
  • Then you still use the backgroundColor but use images of the correct size... Can't think of anything else... – Mika Feb 16 '16 at 21:36
  • thanks for your help :) I'll try around with the image. getting it right for different devices sounds a bit challenging when I have to guess the right size – MikeB Feb 16 '16 at 21:46
  • So what did you end up doing? – Mika Mar 17 '16 at 17:59