我对 SwiftUI 中的 Actionsheet 有疑问。我想创建一个带有 2 个选项的 ActionSheet:删除和取消。“删除”按钮为红色,“取消”为绿色。
这是一个代码示例:
Button(action: {
print("Delete button pressed")
self.showingActionSheet = true
}){
Text("Go to actions")
.foregroundColor(.green)
.font(.body)
.padding()
}
.actionSheet(isPresented: $showingActionSheet) {
return ActionSheet(title: Text("Delete images"), buttons: [
.default(Text("Delete selected").foregroundColor(.red)){
// some action to do
},
.cancel()
])
}
问题是动作的颜色是两个按钮的默认颜色(“蓝色”)。我可以通过在“SceneDelegate.swift”甚至上面的代码中添加以下行来更改它。
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(named: "green")
这条线的问题是它会将一般颜色从“蓝色”覆盖到“绿色”。仍然需要找到如何为每个动作不同颜色的解决方案。
这是它的样子: 图像预览
你有什么建议吗?