如何删除导航链接的背景颜色(灰色的东西)。 我尝试将背景颜色设置为透明,但这似乎没有任何作用:
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()
}
}
}
我找到了解决方案:
导航链接响应色调,而不响应为此目的的 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
)
设置
.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)
还有另一种方法可以实现这一目标 - 您可以在这里找到它。