Skip to content

Instantly share code, notes, and snippets.

@SarahAlsharif
Created August 7, 2020 01:15
Show Gist options
  • Save SarahAlsharif/0080ca52c67b2a033a31be3ba056e0f3 to your computer and use it in GitHub Desktop.
Save SarahAlsharif/0080ca52c67b2a033a31be3ba056e0f3 to your computer and use it in GitHub Desktop.
// 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