gpt4 book ai didi

ios - 在编辑 UITableViewCell 时更改标签颜色

转载 作者:可可西里 更新时间:2023-10-31 23:35:36 26 4
gpt4 key购买 nike

我正在寻找一种在编辑单元格时更改标签颜色的方法。默认颜色为白色,当我滑动删除时会显示该颜色,但我想将其更改为黑色,就像 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]



}

这是默认颜色。 enter image description here

Apple News 就是这样做的。 enter image description here

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

最佳答案

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

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

您可以做的是,您可以使用 UIColor patternImage 方法设置 UITableViewRowAction 实例的背景颜色。

所以它看起来像这样。

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

关于ios - 在编辑 UITableViewCell 时更改标签颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com