简体   繁体   English

更改“ UITableViewRowAction”的颜色

[英]Change the color of 'UITableViewRowAction'

I added this code from the internet and its working. 我从互联网及其工作中添加了此代码。 It shows 2 buttons when swipe the cell, but the buttons are both red. 滑动单元格时,它显示2个按钮,但两个按钮均为红色。 Why? 为什么? How do I change them? 如何更改它们?

在此处输入图片说明

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]
}

You can use the backgroundColor property of the UITableViewRowAction . 您可以使用UITableViewRowActionbackgroundColor属性。 For example, rateAction.backgroundColor = UIColor.blueColor() . 例如, rateAction.backgroundColor = UIColor.blueColor()

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
    var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Aceitar" , handler: {(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        // Put your shareAction handler stuff here
    })
    var rateAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Recusar" , handler: {(action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        // Put your rateAction handler stuff here
    })
    shareAction.backgroundColor = UIColor.redColor()
    rateAction.backgroundColor =  UIColor.blueColor()
    return [shareAction, rateAction]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM