SwiftUI:类似 UITextField 的属性

Ben*_*net 5 textfield swift swiftui

任何人都知道如何自定义 SwiftUI TextField 属性,例如拼写检查类型或自动更正类型?在不与 UIKit 交互的情况下做到这一点似乎是不可能的......

谢谢你们!

Anj*_*iya 2

对于 TextField 或 Text 的自动更正,您可以尝试

struct ContentView: View {

    @State private var name: String = "Angie"
    var body: some View {

            VStack {
                TextField("Enter your name", text: $name)
                Text("Hello, \(name)!")
            }
            .disableAutocorrection(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

我不确定 SwiftUI 中的拼写检查,但您可以查看https://developer.apple.com/documentation/swiftui/textfield进行修改。

希望对您定制TextField有所帮助!

谢谢!!