更改'UITableViewRowAction'的颜色

时间:2015-08-28 14:03:47

标签: ios swift

我从互联网及其工作中添加了此代码。滑动单元格时显示2个按钮,但按钮均为红色。为什么?我该如何改变它们?

enter image description here

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    // 1
    var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Aceitar" , handler: { ( action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        // 2
        let shareMenu = UIAlertController(title: nil, message: "Confirmar Aceitação", preferredStyle: .ActionSheet)

        let twitterAction = UIAlertAction(title: "Twitter", style: UIAlertActionStyle.Default, handler: nil)
        let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil)

        shareMenu.addAction(twitterAction)
        shareMenu.addAction(cancelAction)



        self.presentViewController(shareMenu, animated: true, completion: nil)
    })
    // 3
    var rateAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Recusar" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        // 4
        let rateMenu = UIAlertController(title: nil, message: "Confirmar Recusa", preferredStyle: .ActionSheet)

        let appRateAction = UIAlertAction(title: "Confirmo", style: UIAlertActionStyle.Default, handler: nil)
        let cancelAction = UIAlertAction(title: "Cancelar", style: UIAlertActionStyle.Cancel, handler: nil)

        rateMenu.addAction(appRateAction)
        rateMenu.addAction(cancelAction)


        self.presentViewController(rateMenu, animated: true, completion: nil)
    })
    // 5
    return [shareAction,rateAction]
}

1 个答案:

答案 0 :(得分:5)

您可以使用backgroundColor的{​​{1}}属性。例如,UITableViewRowAction

rateAction.backgroundColor = UIColor.blueColor()