0

如标题所述。我在 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)
          )
    }
}
4

1 回答 1

1

似乎 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)
    )
于 2021-09-24T02:50:45.483 回答