Created
June 20, 2019 00:42
-
-
Save jstheoriginal/ebf298b33cdb4a88c3ac5f17f058aa1f to your computer and use it in GitHub Desktop.
A simple SwiftUI search bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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