gpt4 book ai didi

ios - 如何创建仅在使用 SwiftUI 打开应用程序时出现的警报?

转载 作者:行者123 更新时间:2023-12-04 20:01:26 28 4
gpt4 key购买 nike

我是应用开发的新手,最近开发了一款名为 bullseye 的游戏。

我想在应用程序首次打开时显示一条提醒,向用户提供有关他们将要玩的游戏的说明。

我在没有按钮的情况下在 swiftUI 中创建此警报时遇到问题,想知道是否有人可以帮助我解决这个问题。

PS - 我正在使用 Xcode 11

谢谢

最佳答案

我不是 SwiftUI 专家,但这对我有用:

import SwiftUI

struct ContentView: View {

// In the future, you can use this var to control whether or not to show an alert based on some other condition.
@State var alertShouldBeShown = true

var body: some View {
// attach the alert to the last view in your view hierarchy
Text("Hello, World!").alert(isPresented: $alertShouldBeShown, content: {

Alert(title: Text("Alert:"),
message: Text("This is the alert. :)"),
dismissButton: Alert.Button.default(
Text("OK"), action: {

//

}
)
)
})
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

关于ios - 如何创建仅在使用 SwiftUI 打开应用程序时出现的警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59805456/

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