InputView
和 InputAccessoryView
LeftView
和 RightView
UITextFieldDelegate
方法都作为 SwiftUI
修饰符公开FocusState
的程序化导航ResponderNavigatorView
,可用作 InputAccessoryView
以在文本字段之间导航iOS 15
时的 ParseableFormatStyle
pre-iOS 15
时的 Foundation.Formatter
可以使用 Swift Package Manager 安装 SUITextField
。
在 Xcode 中打开 “File/Swift Packages/Add Package Dependency...” 菜单。
复制并粘贴包 URL
https://github.com/ricocrescenzio95/SUITextField
更多详情请参考 “Adding Package Dependencies to Your App” 文档。
就像使用任何其他 SwiftUI
视图一样使用它!
struct ContentView: View {
enum Responder {
case first
case second
}
@State private var text = "A test text"
@ResponderState var focus: Responder?
@State private var date = Date()
var body: some View {
ScrollView {
VStack {
SUITextField(text: $text, placeholder: "Insert a text...")
.inputAccessoryView {
ResponderNavigatorView(responder: $focus) // add default ResponderNavigatorView as input accessory view
}
.onReturnKeyPressed {
focus = nil // set focus to nil to close keyboard on return key tap
}
.leftView { // add a left view to clear text on tap
Button(action: { text = "" }) {
Image(systemName: "trash")
}
.padding(.horizontal, 2)
}
.responder($focus, equals: .first)
.uiTextFieldTextLeftViewMode(.whileEditing)
SUITextField(text: .constant(date.description))
.inputAccessoryView {
MyAccessoryView() // add a custom accessory view
}
.inputView {
// Use a date picker as input view!
DatePicker("Select date", selection: $date)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.datePickerStyle(.wheel)
.labelsHidden()
}
.responder($focus, equals: .second)
}
.padding()
}
// apply style to all children text field!
.uiTextFieldBorderStyle(.roundedRect)
}
// more code...
使用 Apple DocC
生成的文档,从 Xcode 中选择 “Product > Build Documentation”。
查看此 issue。
如果您发现错误,可以在此处作为错误打开 issue
想要新功能?在此处打开 issue
本软件根据 MIT 许可证提供
感谢 Bebisim ❤️