UITableView custom cell - How to keep cornerRadius in edit mode

自闭症网瘾萝莉.ら 提交于 2020-08-08 04:01:54

问题


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
}

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


回答1:


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) {
}


来源:https://stackoverflow.com/questions/35442819/uitableview-custom-cell-how-to-keep-cornerradius-in-edit-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!