2016-08-19 70 views
3

我正在寻找一种在编辑单元格时更改标签颜色的方法。默认颜色是白色,当我滑动删除时会显示这个颜色,但我想将其更改为黑色,就像苹果新闻应用程序所做的一样,如下图所示。在编辑UITableViewCell时更改标签颜色

这是一般的刷卡编辑代码:

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 



     let editAction = UITableViewRowAction(style: .normal, title: "Rename") { (action: UITableViewRowAction, indexPath: IndexPath) -> Void in 



     } 

     editAction.backgroundColor = UIColor.black 
     return [editAction] 



    } 

这是默认的颜色。 enter image description here

这就是苹果新闻如何做到这一点。 enter image description here

任何想法。我正在使用swift 3,但是任何快速甚至是ObjC都会很酷。谢谢。 ;)

回答

0

我不认为有一个直接的方法来使用UITableViewRowAction来做到这一点。 Apple不允许我们自定义按钮,就像我们在UIButtonUITableViewRowAction中使用的一样。

我有一个想法,让我知道它是否会解决您的问题。让我们说,苹果有一个图像,其中有这三个图标Love,Share & Save [从上述图像的问题]。

您可以做的是,您可以通过使用UIColorpatternImage方法来设置UITableViewRowAction实例的backgroundColor。

所以它看起来像这样。

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

     let discussion = UITableViewRowAction(style: .Normal, title: "") { _, _ in 
     } 

     discussion.backgroundColor = UIColor(patternImage: UIImage(named: "Love&Share&SaveIconsInOneImage")) 

     return [discussion] 
    } 
+0

这看起来很有趣。我将在本周末尝试一下并回复你。 ;) – Gugulethu