如标题所示。我在iOS 14上使用自定义SwiftUI buttonStyle。它可以正常工作,但现在它不能在iOS 15上工作。没有错误,没有警告,我不知道该怎么处理。有人知道怎么修吗?
struct InnerShadowButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
let p = configuration.isPressed
return configuration.label
.overlay (
RoundedRectangle(cornerRadius: 0)
.stroke(Color.clear, lineWidth: 4)
.shadow(color: p ? .gray : .clear, radius: 3, x: 3, y: 3)
.clipShape(RoundedRectangle(cornerRadius: 0))
.opacity(p ? 1.0 : 0.0)
)
}
}
看起来SwiftUI 3根本不画透明矩形,因为你用Color.clear
描边。
你可以用Color.black.opacity(0.001)
:
configuration.label
.overlay (
RoundedRectangle(cornerRadius: 0)
.stroke(Color.black.opacity(0.001), lineWidth: 4)
.shadow(color: p ? .gray : .clear, radius: 3, x: 3, y: 3)
.clipShape(RoundedRectangle(cornerRadius: 0))
.opacity(p ? 1.0 : 0.0)
)