Swiftui 单击图像按钮时,在Swift UI中打开新视图
我想在单击SwiftUI中的图像按钮后打开新视图,有什么想法吗Swiftui 单击图像按钮时,在Swift UI中打开新视图,swiftui,Swiftui,我想在单击SwiftUI中的图像按钮后打开新视图,有什么想法吗 Button(action: {}) { Image("gift") Text("Send") .padding(.horizontal) } .padding() .foregroundColor(.white) .background(Color.gray) .cornerRadius(.infinity) 如果您希望它出现在导航视图中,可以使用导航链接而
Button(action: {}) {
Image("gift")
Text("Send")
.padding(.horizontal)
}
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
如果您希望它出现在
导航视图中
,可以使用导航链接
而不是按钮
:
struct ContentView : View {
var body: some View {
NavigationView {
NavigationLink(destination: DetailView()) {
Image("gift")
Text("Send")
.padding(.horizontal)
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
}
}
}
}
struct DetailView : View {
var body: some View {
Text("Detail")
}
}
如果要显示工作表
,可以使用工作表
修饰符和@State
变量:
struct ContentView : View {
@State private var sheetPresented = false
var body: some View {
Button(action: {
sheetPresented = true
}) {
Image("gift")
Text("Send")
.padding(.horizontal)
}
.padding()
.foregroundColor(.white)
.background(Color.gray)
.cornerRadius(.infinity)
.sheet(isPresented: $sheetPresented) {
DetailView()
}
}
}
struct DetailView : View {
var body: some View {
Text("Detail")
}
}
这么简单你的问题是什么?