Here is the code:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Button(action: {
print("Tapped the button")
}, label: {
Text("Button")
.foregroundStyle(Color.white)
.padding()
.background(Color.gray)
})
.border(Color.green, width: 2)
Image(systemName: "square.and.arrow.up")
.resizable()
.aspectRatio(contentMode: .fill)
.foregroundStyle(Color.black)
.frame(height: 240)
.border(Color.blue, width: 2)
.clipped()
}
.padding()
.border(Color.black, width: 2)
}
}
#Preview {
ContentView()
}
The problem is that the button is not tappable.
Test environment: macOS 15.3.2 (24D81), Xcode Version 16.2 (16C5032a), Simulator: iPhone 16 (18.3.1)
However, if we change the code from ".aspectRatio(contentMode: .fill)" to ".aspectRatio(contentMode: .fit)" then the problem goes away.
Any suggestions to fix the problem?