首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改UITableViewRowAction的颜色

更改UITableViewRowAction的颜色
EN

Stack Overflow用户
提问于 2015-08-28 14:03:46
回答 1查看 1.2K关注 0票数 3

我从互联网上添加了这段代码及其工作原理。它显示了两个按钮时,滑动单元格,但按钮都是红色的。为什么?我该怎么换呢?

代码语言:javascript
复制
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]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-28 14:12:30

您可以使用backgroundColor属性的UITableViewRowAction。例如,rateAction.backgroundColor = UIColor.blueColor()

代码语言:javascript
复制
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]
}
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32272933

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档