Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active Dec 30, 2020
Embed
What would you like to do?
CustomTextField First Responder
import SwiftUI
struct CustomTextField: UIViewRepresentable {
@Binding var text: String
@Binding var isResponder: Bool
func makeUIView(context: UIViewRepresentableContext<CustomTextField>) -> UITextField {
return UITextField(coordinator: context.coordinator)
}
func makeCoordinator() -> CustomTextFieldCoordinator {
return CustomTextFieldCoordinator(text: $text, isResponder: $isResponder)
}
func updateUIView(_ uiView: UITextField, context: UIViewRepresentableContext<CustomTextField>) {
uiView.text = text
uiView.setFirstResponder(isResponder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment