Markdownify

SwiftUI 文本字段

UITextField 的 SwiftUI 封装,允许更多自定义

主要特性安装用法文档许可


主要特性

安装

可以使用 Swift Package Manager 安装 SUITextField

  1. 在 Xcode 中打开 “File/Swift Packages/Add Package Dependency...” 菜单。

  2. 复制并粘贴包 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

您也可以打开您自己的 PR 并为项目做出贡献! 贡献 🤝

许可

本软件根据 MIT 许可证提供


感谢 Bebisim ❤️