How to design custom drop down menu like android in swiftui? [closed] - swift

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 13 days ago.
The community is reviewing whether to reopen this question as of 13 days ago.
Improve this question
I want to show custom drop down menu very attractive view but it does not work when I write the code as I want.
This is drop down menu approach but does not work can anyone tell the solution in any others way also.
struct DropDownList:View{
var body: some View{
Menu(content: {
HStack{
Image(systemName: "eye")
Text("Eye Clinic")
}
HStack{
Image("neuro")
Text("Neuro Hospital")
}
}, label: {
Text("Hospitals")
})
}
}

Your question isn't clear, but the menu you show in the image can be created as follows:
struct ContentView: View {
var body: some View {
HStack {
Text("Something")
DropDownList()
}
}
}
struct DropDownList:View {
var body: some View {
Menu {
Button {
} label: {
Label("Edit", systemImage: "square.and.pencil")
}
Button {
} label: {
Label("Delete", systemImage: "trash")
}
} label: {
Image(systemName: "ellipsis")
}
}
}

Related

Showing and hiding views with transitions in swiftui [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
i try to make 'showing and hiding views with transitions' in Animations (with swiftUI) ;
import SwiftUI
struct ContentView: View {
#State private var isShowingRed = false
var body: some View {
VStack {
Button("tap me") {
withAnimation {
isShowingRed.toggle()
}
}
if isShowingRed {
Rectangle()
.fill(.red)
.frame(width: 200, height: 200)
transition(.asymmetric(insertion: .scale, removal: .opacity))
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
but got error like ;
An unknown crash has occurred, check back for more information. How to fix that erro,any idea?
Thanks.
It looks like you forgot to put a . before transition(.asymmetric(insertion: .scale, removal: .opacity)).
That might be why.

How do I implement a loading animation with SwiftUI? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I already have an animation made in AfterEffects that I think Lottie can turn into a format I can use for my app. What I am wondering is how can I make the app start performing this animation when it is opened until the app is done loading?
Simply show the animation view instead of your content view while it's loading
example:
struct ContentView: View {
#State var isLoading = true
var body: some View {
VStack {
if isLoading {
LoadingView()
} else {
DoneLoadingView()
}
}.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
isLoading = false
}
}
}
}
struct LoadingView: View {
var body: some View {
ProgressView()
}
}
struct DoneLoadingView: View {
var body: some View {
VStack {
Text("Hello, world!")
}
}
}

I want to move to the first screen with NavigationLink in SwiftUI [duplicate]

This question already has answers here:
How can I pop to the Root view using SwiftUI?
(31 answers)
Closed 2 years ago.
The screen transitions with NavigationLink.
I want to return to the first screen by clicking the button on the third screen.
How do you do it?
The following code returns from the third screen to the second screen.
struct FirstView: View {
var body: some View {
VStack {
NavigationView {
NavigationLink(
destination: SecondView()
) {
Text("next")
}
}
}
}
}
struct ThirdView: View {
#Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
var body: some View {
VStack {
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Text("next")
}
}
.navigationBarTitle("Third", displayMode: .inline)
}
}
I had encountered this problem, too.
But I solved it already.
Here is the solution.
Maybe it can work.
Check this answer

How to add a Button below a List in SwiftUI? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
how can I add a Button in SwiftUI below a List so that it looks like in the Note app:
I tried it with a Stack but this did not work.
Here is simple demo:
struct DemoListWithButton: View {
var body: some View {
NavigationView {
VStack(alignment: .trailing) {
List(0..<100) { i in
Text("Item \(i)")
}
.navigationBarTitle("Title")
Button("Button") {}
.padding()
}
}
}
}
struct DemoListWithButton_Previews: PreviewProvider {
static var previews: some View {
DemoListWithButton()
}
}

How to use the NavigationView and NavigationLink [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am setting NavigationLink for Item,but not work with image disappeared.
struct Items: View {
var landmarks: [Landmark]
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
//NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
//}
}
}
}
}
}
You have to embed your Scrollview into a NavigationView or it will not work
struct Items: View {
var landmarks: [Landmark]
var body: some View {
NavigationView {
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(landmarks) { landmark in
//加了这个导航就看不到图片了,CategoryHome 也不显示图片,
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
Item(landmark: landmark)
}
}
}
}
}
}
}
Here is the apple tutorial for creating navigation is SwiftUI