I want to create a dropdown-menu in Xcode 11 Beta 1. But i have not found a way to to it in iOS.
I have tried it with the .hidden function and found the PullDownButton, but don‘t know how to set it up
I have created this Code
struct SwiftUIView : View {
@State var array = true
@State var buttonTitle = "Zeige Deteils"
var body: some View {
VStack {
VStack {
Button(action: {
self.array.toggle()
}) {
Text(buttonTitle)
}
if array {
VStack(spacing: 1.0) {
Button(action: {
self.buttonTitle = "Schmelzpunkt"
self.array.toggle()
}) {
Text("Schmelzpunkt")
.color(.white)
.padding(.all)
}
.background(Color.blue)
Button(action: {
self.buttonTitle = "Instrumentelle Analytik"
self.array.toggle()
}) {
Text("Instrumentelle Analytik")
.color(.white)
.padding(.all)
}.background(Color.blue)
Button(action: {
self.buttonTitle = "Aussehen"
self.array.toggle()
}) {
Text("Aussehen")
.color(.white)
.padding(.all)
}.background(Color.blue)
}
.padding(.top)
}
}
}
}
But can't find a was to animate the "poping-up" auf the hidden Buttons and want to the primary button to stay at its position
Example Explained. Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.
Let's add the @State var to our ContentView . Now, let's create the sidebar view by creating a new SwiftUI file. Go to File → New → File or press ⌘ + N to create a new file. Select the type of file you want to create, select SwiftUI View, and click Next.
In SwiftUI 2.0 (iOS 14+) you can make a dropdown menu with Menu
.
Menu {
Button {
style = 0
} label: {
Text("Linear")
Image(systemName: "arrow.down.right.circle")
}
Button {
style = 1
} label: {
Text("Radial")
Image(systemName: "arrow.up.and.down.circle")
}
} label: {
Text("Style")
Image(systemName: "tag.circle")
}
Using SwiftUI 2.0
you can also implement dropdown menu with DisclosureGroup
here is ref.
GroupBox {
DisclosureGroup("Menu 1") {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With