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

问题描述 投票:0回答:1

这里首次尝试使用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)
macos button swiftui
1个回答
0
投票

通过如下配置按钮来使其平方:

Button(action: {
        self.calculatorVM.recieveInput(self.button)
    }) {
        Text(button.title)
            .font(.body)
            .frame(width: buttonWidth, height: 50)
            .background(button.buttonHeight)
}
.buttonStyle(PlainButtonStyle())
© www.soinside.com 2019 - 2024. All rights reserved.