单击 xcode / Swift UI 时如何更改导航链接的不透明度

Mak*_*koi 2 user-interface xcode swiftui

我设置了一个带有图像的导航链接,默认情况下,当用户按下导航链接时,图像的不透明度会降低到 30-40% 左右。

我想知道如何防止这种情况发生以及如何将不透明度设置为我需要的任何值。

我的代码:

NavigationLink(destination:
    PostPageView()
    .navigationBarTitle(Text("Post"), displayMode: .inline)
    .foregroundColor(Color("blackAndWhite"))
  ){
    Image("partyyy").resizable().frame(height: 300)

  }
Run Code Online (Sandbox Code Playgroud)

您可以在下面看到带有示例的图像。感谢你的帮助!

图片示例

Dan*_*iel 5

您可以创建自己的按钮样式并将其添加到 NavigationLink。

.buttonStyle(MyButtonStyle())

为自定义样式创建一个结构,如下所示:

    struct MyButtonStyle: ButtonStyle {
    public func makeBody(configuration: MyButtonStyle.Configuration) -> some View {
        configuration.label
            .opacity(configuration.isPressed ? 1 : 1)

            // You can also add other animated properties
            .scaleEffect(configuration.isPressed ? 0.8 : 1)
    }
}
Run Code Online (Sandbox Code Playgroud)