【问题标题】:Changing the label colour in editing a UITableViewCell在编辑 UITableViewCell 时更改标签颜色
【发布时间】:2016-12-26 07:35:26
【问题描述】:

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

这是编辑代码的常用滑动:

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]



    }

这是默认颜色。

这就是苹果新闻的做法。

任何想法。我正在使用 swift 3,但 swift 甚至 ObjC 中的任何东西都会很酷。谢谢。 ;)

【问题讨论】:

    标签: ios swift uitableview swift3


    【解决方案1】:

    我认为没有直接的方法可以通过使用UITableViewRowAction 来做到这一点。 Apple 不允许我们像在 UIButton 中使用 UITableViewRowAction 那样自定义按钮。

    我有一个想法,让我知道它是否能解决您的问题。假设 Apple 有一张图片,其中包含这三个图标 LoveShareSave [来自问题中的上图]。

    你可以做的是,你可以使用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]
        }
    

    【讨论】:

    • 这看起来很有趣。我打算在这个周末试一试,然后回复你。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多