I am trying to create a custom frame for a background image on my UIButton. Here is my code so far:
struct MSButton: UIViewRepresentable {
var label: String
var action: (() -> Void)?
init(_ label: String, action: @escaping () -> Void) {
self.label = label
self.action = action
}
func makeUIView(context: Context) -> UIButton {
let button = UIButton()
button.setTitle(label, for: .normal)
button.setBackgroundImage(UIImage(named: "button.png"), for: .normal) // Where I'm trying to add the custom frame.
return button
}
func updateUIView(_ uiView: UIButton, context: Context) {
}
}
How would I go about doing this? Currently, the preview just shows the background image stretching to the entire screen.
