我正在尝试为我的UIButton上的背景图像创建自定义框架。到目前为止,我的代码如下:
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) {
}
}
我该如何着手做这件事呢?目前,预览只显示延伸到整个屏幕的背景图像。
1条答案
按热度按时间vx6bjr1n1#
我在这个问题上遇到了很多麻烦,但以下是我设法做到的