如何使按钮的可点击区域成为按钮框架

时间:2020-04-08 00:06:02

标签: macos button swiftui

这里首先尝试使用SwiftUI,将Swift Macos应用程序转换为SwiftUI。

我想知道是否可以将Buttons框架中的整个区域作为按钮的一部分单击。似乎只有文字周围突出显示的区域才是按钮的一部分。

Buttons

其中一个计算器按钮的代码:

Button("÷", action: {
    self.calculatorVM.operate("÷")
})
    .frame(width: self.calculatorVM.buttonWidth, height: self.calculatorVM.buttonHeight)
    .border(Color.blue)
    .font(.body)

1 个答案:

答案 0 :(得分:0)

按如下所示配置按钮,使它方形化:

Button(action: {
        self.calculatorVM.recieveInput(self.button)
    }) {
        Text(button.title)
            .font(.body)
            .frame(width: buttonWidth, height: 50)
            .background(button.buttonHeight)
}
.buttonStyle(PlainButtonStyle())