gpt4 book ai didi

ios - UISwipeActionsConfiguration/UIContextualAction with icon AND text AND clear background

转载 作者:可可西里 更新时间:2023-11-01 05:42:54 27 4
gpt4 key购买 nike

那里有几个类似的问题(例如 my previous iOS10 variant ),但我认为应该有一个针对 iOS 11 的最新答案,使用 Swift4,不使用私有(private) API,也不依靠你将你的图标限制为 unicode 表情符号。

随着 API 向 iOS11 的发展,我们现在可以放置图像和文本,但它们被迫进入模板模式并使用您设置的任何背景颜色进行反向着色。例如

let rename = UIContextualAction(style: .normal, title: "Rename") { (_, view, _) in
self.renameEntry(indexPath)
}
rename.backgroundColor = UIColor.black
rename.image = UIImage(named: "pencilEdit")
let locate = UIContextualAction(style: .normal, title: "Locate") { (_, view, _) in
self.locateEntry(indexPath)
}
locate.backgroundColor = UIColor.blue
locate.image = UIImage(named: "locatePin")
let delete = UIContextualAction(style: .destructive, title: "Forget") { (_, view, _) in
self.deleteEntry(indexPath)
}
delete.backgroundColor = UIColor.red
delete.image = UIImage(named: "triggerDeleteSelector")
return UISwipeActionsConfiguration(actions: [rename, locate, delete])

产生这个:

enter image description here

显然,我们可以有图像或文本,但不能同时有。

但是我想要的样子是

enter image description here

除了倒序,我不知道如何像我在 iOS10 上那样欺骗系统。我仍然可以生成包含文本和图像的图像,但我无法控制该图像的颜色。将 backgroundColor 设置为 nil 或 .clear 只会生成空方 block 。

最佳答案

使用 patternImage 设置背景颜色,不设置标题或图像。这是一个 hacky 技巧,但它应该适合您的情况。

let rename = UIContextualAction(style: .normal, title: nil) { (_, view, _) in 
self.renameEntry(indexPath)
}
rename.backgroundColor = UIColor(patternImage: UIImage(named: "pencilEditWideFrame")!)

你必须用最左边的图标保存像这样的宽帧图像,这样它们实际上就不会重复:

enter image description here

注意:我对此进行了测试,它在使用两个或多个上下文操作时有效,但不适用于一个。该模式最终会在完全滑动时重复。

这还假设您的 tableview 后面有一个纯背景,您可以将其用作图像的背景颜色,因为透明度仍然是不行的。

关于ios - UISwipeActionsConfiguration/UIContextualAction with icon AND text AND clear background,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47320094/

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