Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. struct SearchBar: UIViewRepresentable {
  2.  
  3. @Binding var text: String
  4.  
  5. class Coordinator: NSObject, UISearchBarDelegate {
  6.  
  7. @Binding var text: String
  8.  
  9. init(text: Binding<String>) {
  10. _text = text
  11. }
  12.  
  13. func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
  14. text = searchText
  15. }
  16. }
  17. func makeCoordinator() -> SearchBar.Coordinator {
  18. return Coordinator(text: $text)
  19. }
  20.  
  21. func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar {
  22. let searchBar = UISearchBar(frame: .zero)
  23. searchBar.delegate = context.coordinator
  24. searchBar.autocapitalizationType = .none
  25. return searchBar
  26. }
  27.  
  28. func updateUIView(_ uiView: UISearchBar, context: UIViewRepresentableContext<SearchBar>) {
  29. uiView.text = text
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement