Skip to content

Instantly share code, notes, and snippets.

@dfrobison
Last active February 4, 2020 19:53
Show Gist options
  • Save dfrobison/7f20465a774ae5e7e93e856cd891d128 to your computer and use it in GitHub Desktop.
Save dfrobison/7f20465a774ae5e7e93e856cd891d128 to your computer and use it in GitHub Desktop.
[Dropdown menu for SwiftUI] from Kavsoft (https://www.youtube.com/watch?v=CwD4cScGCq8)
struct DropDown: View {
@State var expand = false
var body: some View {
VStack(alignment: .leading, spacing: 18, content: {
HStack {
Text("Expand").fontWeight(.heavy).foregroundColor(.white)
Image(systemName: expand ? "chevron.up" : "chevron.down").resizable().frame(width: 13, height: 6).foregroundColor(.white)
}
.onTapGesture {
self.expand.toggle()
}
if expand {
Button(action: {
self.expand.toggle()
}) {
Text("Select 1")
}.foregroundColor(.white)
Button(action: {
self.expand.toggle()
}) {
Text("Select 2")
}.foregroundColor(.white)
Button(action: {
self.expand.toggle()
}) {
Text("Select 3")
}.foregroundColor(.white)
}
})
.padding()
.background(LinearGradient(gradient: .init(colors: [.red, .orange]), startPoint: .top, endPoint: .bottom))
.cornerRadius(20)
.animation(.spring())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment