[英]How can I create a popup menu in iOS?
如何创建像 WhatsApp 中那样的弹出菜单?
抱歉这个愚蠢的问题,但我什至不知道要搜索什么。 我很确定它不是UIPickerView
。
你可以做一个这样的:
使用confirmationDialog()
。 这里是它的官方文档, 这里有一些真实世界的例子,它们是示例代码的部分来源。
@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.