【发布时间】:2021-01-13 09:55:22
【问题描述】:
我有一个由图像和一些文本组成的 NavigationLink,我想在按下链接时更改图像的边框颜色。
这是导航链接:
NavigationLink(destination: TrickSelectView()) {
HStack{
Image("learnTricksButton")
.resizable()
.clipShape(Circle())
.overlay(Circle().stroke(Color(red: 0.95, green: 0.32, blue: 0.34), lineWidth: 4))
.shadow(radius: 7)
.frame(width: width, height: width)
VStack{
Text("Trick")
.font(.system(.largeTitle, design: .rounded))
.foregroundColor(Color(red: 0.13, green: 0.15, blue: 0.22))
Text("Personalise your learning!")
.font(.system(.subheadline, design: .rounded))
.foregroundColor(Color(red: 0.28, green: 0.32, blue: 0.37))
}
}.padding(.bottom, 50)
}.buttonStyle(LearnButtonEffect())
这是迄今为止我得到的按钮样式:
struct LearnButtonEffect: ButtonStyle {
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.background(configuration.isPressed ? Color.green.opacity(0.5) : Color.green)
.shadow(color: Color.gray, radius: 10, x: 0, y: 0)
.scaleEffect(configuration.isPressed ? 0.9 : 1.0)
}
}
一般来说,我想知道如何在按钮样式定义中引用 NavigationLink 的特定部分(在本例中为图像的边框)。
【问题讨论】:
标签: animation button swiftui swiftui-navigationlink