如何去除NavigationLinks中的背景?

问题描述 投票:0回答:2

如何删除导航链接的背景颜色(灰色的东西)。 我尝试将背景颜色设置为透明,但这似乎没有任何作用:

struct DesignView: View {

@State var index: Int
@State var selection: Int


var body: some View {
    ZStack(alignment: .center){
        RoundedRectangle(cornerRadius: 90.0)
            .fill(Color.white)
            .frame(height: 50)
        
        NavigationLink(
                destination: GraphView(type: selection, index: index),
                label: {
                    Text("Warm Up #\(index)")
                        .font(.system(size: 20, weight: .bold, design: .rounded))
                        .foregroundColor(.black)
                        .backgroundStyle(
                            Color.clear
                        )
                })
        .backgroundStyle(
            Color.clear
        )
   
        .padding()
    }
}
}
ios swift swiftui navigationview
2个回答
0
投票

我找到了解决方案:

导航链接响应色调,而不响应为此目的的 bcgrnd 颜色:

NavigationLink(
                destination: GraphView(type: selection, index: index),
                label: {
                    Text("Warm Up #\(index)")
                        .font(.system(size: 20, weight: .bold, design: .rounded))
                        .foregroundColor(.black)
                        .backgroundStyle(
                            Color.clear
                        )
                })
        .tint(Color.clear)
        .backgroundStyle(
            Color.clear
            
        )

0
投票

设置

.backgroundStyle(Color.clear)
.tint(Color.clear)
对我来说不起作用。在导航链接上使用
.buttonStyle(.plain)

NavigationLink(
    destination: GraphView(type: selection, index: index),
    label: {
        Text("Warm Up #\(index)")
            .font(.system(size: 20, weight: .bold, design: .rounded))
                .foregroundColor(.black)
    })
.buttonStyle(.plain)

还有另一种方法可以实现这一目标 - 您可以在这里找到它。

© www.soinside.com 2019 - 2024. All rights reserved.