UITableView自定义单元格 - 如何在编辑模式下保持cornerRadius

3
我使用自定义单元格实现了一个TableView。这些单元格的cornerRadius被设置为2。一切都显示得很好,直到我进入编辑模式。当删除按钮出现时,它的角半径为0。
如何使删除按钮也有圆角?
我尝试过这个方法,但没有成功:
func tableView(tableView: UITableView, willBeginEditingRowAtIndexPath indexPath: NSIndexPath) {
    let cell = tableView.cellForRowAtIndexPath(indexPath)
    cell!.editingAccessoryView?.layer.cornerRadius = 2
}

当前,我的Storyboard中的角落半径是作为用户定义的运行时属性设置的。
请参考以下图片:enter image description here 此外,还有另一张图片可供参考:enter image description here

请在Storyboard截图中为圆角添加用户定义的运行时属性。 - Nishant
将其添加到我的问题中。 - MikeB
另外,在 cellForRowAtIndexPath 中尝试使用 cell.clipToBounds = true - Nishant
在使用自定义单元格的cellForRowAtIndexPath方法中无法实现... 我已经在CustomCell.swift文件中将clipToBounds设置为true,但没有任何变化... - MikeB
1个回答

0

你可以像这样操作按钮:

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

类型“UITableViewRowAction”没有成员“layer”的值 - 不起作用...找不到获取按钮视图的方法 - MikeB
原來 UITableViewRowAction 並未繼承自 UIButton... 我錯了... 在這種情況下,你必須使用 backgroundColor 屬性。我會添加更多的代碼。 - Mika
非常感谢您的帮助!背景颜色的想法很棒!不幸的是,UITableViewRowAction也没有视图属性。它唯一拥有的属性是样式、标题、背景颜色和背景效果。这些属性都不能用来获取大小... - MikeB
那么你仍然可以使用backgroundColor,但要使用正确尺寸的图像... 想不出其他的了... - Mika
谢谢你的帮助 :) 我会尝试调整图片。当我必须猜测正确的大小以适应不同的设备时,这听起来有点具有挑战性。 - MikeB
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接