【发布时间】:2023-03-10 13:00:01
【问题描述】:
我正在尝试构建一个 SwiftUI Textfield,它应该可以在整个灰色区域中单击以输入文本(为了更好地可视化,我做了一个红框)。
作为占位符的“搜索”一词应在此框内居中以使其看起来更好。
我的问题是,在“搜索”一词下方和上方的整个区域中,该框不可点击。
struct ContentView: View {
@State private var searchText = ""
var body: some View {
HStack {
Image(systemName: "magnifyingglass")
Spacer()
TextField("Search", text: self.$searchText).foregroundColor(.primary)
.frame(height: 40).border(Color.red) //This line is just to show what I want to achive to be clickable.
Spacer()
}
.foregroundColor(.secondary)
.background(Color(.secondarySystemBackground))
.cornerRadius(10.0)
}
}
【问题讨论】:
-
很遗憾,您不能这样做。但是我会看看我是否可以想出一个解决方法,如果我可以的话,我会回复你的:)