A simple SwiftUI search bar
struct SearchBar : View { | |
@Binding var searchText: String | |
var body: some View { | |
HStack { | |
Image(systemName: "magnifyingglass").foregroundColor(.secondary) | |
TextField( | |
$searchText, | |
placeholder: Text("Search")) { | |
UIApplication.shared.keyWindow?.endEditing(true) | |
} | |
Button(action: { | |
self.searchText = "" | |
}) { | |
Image(systemName: "xmark.circle.fill").foregroundColor(.secondary).opacity(searchText == "" ? 0 : 1) | |
} | |
}.padding(.horizontal) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment