Skip to content

Instantly share code, notes, and snippets.

@perpeer
Last active September 6, 2022 16:51
Show Gist options
  • Select an option

  • Save perpeer/086932ad74fcc7e0e927090d65b91193 to your computer and use it in GitHub Desktop.

Select an option

Save perpeer/086932ad74fcc7e0e927090d65b91193 to your computer and use it in GitHub Desktop.
SwiftUI Keyboard Close Button
extension TextField {
func showCloseKeyboardButton() -> some View {
self.toolbar {
ToolbarItemGroup(placement: .keyboard) {
Spacer()
Button {
UIApplication.shared.endEditing()
} label: {
Image(systemName: "keyboard.chevron.compact.down")
}
}
}
}
}
extension UIApplication {
func endEditing() {
sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment