我在SwiftUI文件中定义了一个自定义按钮,如下所示。
struct CircleButtonWithIcon: View {
@State private var navigateToHomePage = false
var body: some View {
Button(action: {
}) {
Image(systemName: "arrow.right")
.font(.system(size: 24))
.foregroundColor(.white)
.padding(20)
.background(Color(#colorLiteral(red: 1, green: 0.3607843137, blue: 0.003921568627, alpha: 1)))
.clipShape(Circle())
.overlay(
Circle()
.stroke(Color.white, lineWidth: 3)
)
}
}
}
我正在尝试导航到下一页如下。
import SwiftUI
struct WelcomeView: View {
@State private var navigateToHomePage = false
var body: some View {
NavigationView {
ZStack {
Image("WelcomeBackground")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(minWidth: 0, maxWidth: .infinity)
.edgesIgnoringSafeArea(.all)
VStack(alignment: .center) {
Spacer()
ZStack(alignment: .center) {
VStack {
VStack {
HStack {
Text("No Worry,")
.font(.title)
.foregroundColor(.white)
.fontWeight(.bold)
Text("Handle")
.font(.title)
.foregroundColor(.white)
.fontWeight(.regular)
}
HStack {
Text("Your Hunger,")
.font(.title)
.foregroundColor(.white)
.fontWeight(.regular)
Text("With")
.font(.title)
.foregroundColor(.white)
.fontWeight(.bold)
}
Text("Eattak!")
.font(.title)
.foregroundColor(.white)
.fontWeight(.bold)
Text("Eattak come to help you hunger problem with easy find any restaurant")
.font(.body)
.foregroundColor(.white).padding().multilineTextAlignment(.center)
}
.padding()
NavigationLink(destination: HomeView()) {
CircleButtonWithIcon()
}
}
.padding(.bottom,100)
}
}.background(
Image("welcome-black-shadow")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(minWidth: 0, maxWidth: .infinity)
)
.foregroundColor(.white)
.padding(.horizontal, 24)
}
}
}
}
我已经添加了NavigationView
,并在里面添加了NavigationLink
,但在按钮单击它不是导航到下一页。
我看了所有的问题,但没有一个有帮助
谢谢
1条答案
按热度按时间muk1a3rh1#
我不认为
NavigationLink
应该和Button
一起使用。尝试将NavigationLink
中的按钮视图替换为其标签(图像):希望这能帮上忙。