mea*_*ers 4 keyboard textfield ios swift swiftui
我尝试使用 SwiftUI TextField 并希望摆脱键盘上方的预测建议栏:
struct ContentView: View {
@State private var text: String = ""
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
TextField("Hello", text: $text)
.autocorrectionDisabled()
.textContentType(.init(rawValue: ""))
}
.padding()
}
}
Run Code Online (Sandbox Code Playgroud)
打字时,预测建议仍然显示在键盘上方。有没有办法摆脱这些呢?
您需要使用autocorrectionDisabled而不是disableAutocorrection添加,.textContentType(.init(rawValue: ""))并且不要忘记将键盘设置为.keyboardType(.asciiCapable)。默认键盘不起作用。我不知道为什么。
struct ContentView: View {
@State private var text: String = ""
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
TextField("Hello", text: $text)
.keyboardType(.asciiCapable)
.autocorrectionDisabled(true)
.textContentType(.init(rawValue: ""))
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
722 次 |
| 最近记录: |