英文:
macOS-provided control to enter simple text
问题
macOS是否有内置的方法来要求用户在UI/窗口中输入字符串?
类似于Chrome的默认文本输入UI:
还是我需要创建自己的?
英文:
Is there a built-in way in macOS to ask a user to enter a string in a UI/window?
Similar to this default text input UI for Chrome:
Or, do I need to create my own?
答案1
得分: 1
这是一个警告。在 macOS 中,您可以添加一个 TextField
来获取值:
@State private var showingAlert = false
@State private var input = ""
var body: some View {
Button("Show Alert") {
showingAlert = true
}
.alert("The page at blah blah blah...", isPresented: $showingAlert) {
TextField("What's your sign?", text: $input)
Button("OK") {}
}
}
请注意,我已将代码中的 HTML 实体字符 "
替换为正常的引号字符。
英文:
That is an alert. In macOS, you can add a TextField
to get the value:
@State private var showingAlert = false
@State private var input = ""
var body: some View {
Button("Show Alert") {
showingAlert = true
}
.alert("The page at blah blah blah...", isPresented: $showingAlert) {
TextField("What's your sign?", text: $input)
Button("OK") {}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论