gpt4 book ai didi

ios - 如何在 iOS 中创建弹出菜单?

转载 作者:行者123 更新时间:2023-11-30 12:06:22 25 4
gpt4 key购买 nike

如何创建像 WhatsApp 中那样的弹出菜单?

Screenshot of the popup menu

很抱歉问了这个愚蠢的问题,但我什至不知道要搜索什么。我很确定它不是 UIPickerView

最佳答案

这是一个操作表Here's the documentation有关它的信息,请参阅 iOS 人机界面指南。

你可以像这样制作一个:

SwiftUI(iOS 15 及更高版本)

使用confirmationDialog()Here is the official documentation for ithere 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) { }
}

SwiftUI(iOS 13 和 14)

@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()
]
)
}

UIKit

let alert = UIAlertController(
title: nil,
message: nil,
preferredStyle: .actionSheet
)

alert.addAction(
.init(title: "Action 1", style: .default) { _ in
<handler>
}
)

alert.addAction(
.init(title: "Action 2", style: .default) { _ in
<handler>
}
)

alert.addAction(.init(title: "Cancel", style: .cancel))

present(alert, animated: true)

关于ios - 如何在 iOS 中创建弹出菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46633499/

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