[英]How can I create a popup menu in iOS?
How can I create a popup menu like the one present in WhatsApp?如何创建像 WhatsApp 中那样的弹出菜单?
Sorry for the dumb question, but I don't even know what to search.抱歉这个愚蠢的问题,但我什至不知道要搜索什么。 I'm pretty sure it's not a UIPickerView
.我很确定它不是UIPickerView
。
This is an action sheet .这是一个行动表。 Here's the documentation about it in the iOS Human Interface Guidelines. 这是iOS 人机界面指南中有关它的文档。
You can make one like this:你可以做一个这样的:
Use confirmationDialog()
.使用confirmationDialog()
。 Here is the official documentation for it and here are some real-world examples, which are partially the source of the example code. 这里是它的官方文档, 这里有一些真实世界的例子,它们是示例代码的部分来源。
@State private var shouldShowActionSheet = false
<custom view>
.confirmationDialog("", isPresented: $shouldShowActionSheet) {
Button("Option 1") {
<handler>
}
Button("Option 2") {
<handler>
}
Button("Cancel", role: .cancel) { }
}
@State private var shouldShowActionSheet = false
[...]
<custom view>
.actionSheet(isPresented: $shouldShowActionSheet) {
ActionSheet(
title: Text(""),
buttons: [
.default(Text("Option 1")) {
<handler>
},
.default(Text("Option 2")) {
<handler>
},
.cancel()
]
)
}
let alert = UIAlertController(
title: nil,
message: nil,
preferredStyle: .actionSheet
)
alert.addAction(
.init(title: "Action 1", style: .default) { _ in
<handler>
}
)
alert.addAction(
.init(title: "Action 1", style: .default) { _ in
<handler>
}
)
present(alert, animated: true)
它的UIAlertController
与 preferredStyle - UIAlertControllerStyle.actionSheet
https://developer.apple.com/documentation/uikit/uialertcontroller
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.