Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct SearchBar: UIViewRepresentable {
- @Binding var text: String
- class Coordinator: NSObject, UISearchBarDelegate {
- @Binding var text: String
- init(text: Binding<String>) {
- _text = text
- }
- func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
- text = searchText
- }
- }
- func makeCoordinator() -> SearchBar.Coordinator {
- return Coordinator(text: $text)
- }
- func makeUIView(context: UIViewRepresentableContext<SearchBar>) -> UISearchBar {
- let searchBar = UISearchBar(frame: .zero)
- searchBar.delegate = context.coordinator
- searchBar.autocapitalizationType = .none
- return searchBar
- }
- func updateUIView(_ uiView: UISearchBar, context: UIViewRepresentableContext<SearchBar>) {
- uiView.text = text
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement