我想在SwiftUI中实现SwiftUI新变形按钮,但是阴影被弄乱了。要解决此问题,我使用blendmode(overlay),但是它对NavBar中的按钮没有影响。它在常规视图中的按钮上工作正常。 The problem
这是我的代码
struct ContentView: View {
var body: some View {
NavigationView{
Button("Hi") { }
.foregroundColor(Color.primary)
.padding()
.background(
ZStack {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.shadow(
color: .white,
radius: 12,
x: -6,
y: -8
)
.shadow(
color: Color.black.opacity(0.8),
radius: 12,
x: 6,
y: 8
)
.blendMode(.overlay)
.padding(2)
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(color)
}
)
.navigationBarColor(UIbackground)
.navigationBarTitle("SwiftUI")
.frame(minWidth: 0, maxWidth: .infinity,
minHeight: 0, maxHeight: .infinity,
alignment: .center)
.background(color)
.navigationBarItems(leading: Button("Hi") { }
.foregroundColor(Color.primary)
.padding()
.background(
ZStack {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.shadow(
color: .white,
radius: 12,
x: -6,
y: -8
)
.shadow(
color: Color.black.opacity(0.8),
radius: 12,
x: 6,
y: 8
)
.blendMode(.overlay)
.padding(2)
RoundedRectangle(cornerRadius: 12, style: .continuous)
.foregroundColor(color)
}
))
}
}
}
任何帮助将不胜感激。