2016-08-19 73 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