SwiftUI 无边框图像按钮

SwiftUI Image-Button without Border


我试图在 **SwiftUI** 中创建一个可点击的 **Image**,在浏览了几个网页后,我发现了这段代码:
Button(action: {
            toggleWidth()
        }) {
            Image(systemName: "chevron.right")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 20, height: 20)
                .cornerRadius(40)
                .buttonStyle(BorderlessButtonStyle())
        }

创建以下输出: Buttons

无论我想做什么,我似乎都无法消除按钮本身的填充。 仅显示图像的按钮我缺少什么?

不是 100% 确定你在问什么,但也许你可以试试这个:

Button(action: {
    toggleWidth()
}) {
    Image(systemName: "chevron.right")
        .resizable()
        .aspectRatio(contentMode: .fill)
        .frame(width: 20, height: 20)
        .cornerRadius(40)
}.buttonStyle(BorderlessButtonStyle())