UITableView 自定义单元格 - 如何将cornerRadius 保持在编辑模式 [英] UITableView custom cell - How to keep cornerRadius in edit mode

查看:28
本文介绍了UITableView 自定义单元格 - 如何将cornerRadius 保持在编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个带有自定义单元格的表格视图.单元格的cornerRadius 设置为2.一切显示正常,直到我进入编辑模式.当删除按钮出现时,它的角半径为0.

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.

如何让删除按钮也有一个cornerRadius?

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.

推荐答案

你可以这样操作按钮:

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

这篇关于UITableView 自定义单元格 - 如何将cornerRadius 保持在编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆