It looks like Xcode 16 has changed this behaviour so I'm not sure if this is a bug or not.
When a SwiftUI Button
wraps a UIImageView
and the button style is .plain
the button doesn't work without setting isUserInteractionEnabled
.
struct ContentView: View {
var body: some View {
Button {
print("Hello World!")
} label: {
UITestImage()
}
.buttonStyle(.plain)
}
}
struct UITestImage: UIViewRepresentable {
func makeUIView(context: Context) -> UIImageView {
let view = UIImageView()
// view.isUserInteractionEnabled = true // Fix
view.image = UIImage(systemName: "plus")
view.contentMode = .scaleAspectFit
view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
view.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
view.layoutMargins = .zero
return view
}
public func updateUIView(_ uiView: UIImageView, context: Context) {}
}
This feels unexpected, is this a bug?