Created
August 7, 2020 01:15
-
-
Save SarahAlsharif/0080ca52c67b2a033a31be3ba056e0f3 to your computer and use it in GitHub Desktop.
This file contains 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
// Search view | |
HStack { | |
HStack { | |
//search bar magnifying glass image | |
Image(systemName: "magnifyingglass").foregroundColor(.secondary) | |
//search bar text field | |
TextField("search", text: self.$searchText, onEditingChanged: { isEditing in | |
self.showCancelButton = true | |
}) | |
// x Button | |
Button(action: { | |
self.searchText = "" | |
}) { | |
Image(systemName: "xmark.circle.fill") | |
.foregroundColor(.secondary) | |
.opacity(self.searchText == "" ? 0 : 1) | |
} | |
} | |
.padding(8) | |
.background(Color(.secondarySystemBackground)) | |
.cornerRadius(8) | |
// Cancel Button | |
if self.showCancelButton { | |
Button("Cancel") { | |
UIApplication.shared.endEditing(true) | |
self.searchText = "" | |
self.showCancelButton = false | |
} | |
} | |
} | |
.padding([.leading, .trailing,.top]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment