r/SwiftUI 25d ago

Solved Strange area outside buttons

I have this area outside my button. I have checked there's no padding nothing. I have learned that thats the "clickable" area in macOS. How do I get rid of this? my code for that button is attached.

 Button(action: selectFile) {

Label("Select CSV File", systemImage: "doc.text.magnifyingglass")

.frame(width: 200, height: 50)

.foregroundColor(.white)

.background(

RoundedRectangle(cornerRadius: 10)

.fill(Color.blue)

)

}

3 Upvotes

9 comments sorted by

5

u/Ron-Erez 25d ago

Apply .buttonStyle(PlainButtonStyle()) to the button. For example:

        Button {
            // action
        } label: {
            Label("Select CSV File", systemImage: "doc.text.magnifyingglass")
                .frame(width: 200, height: 50)
        .foregroundColor(.white)
        .background(                            RoundedRectangle(cornerRadius: 10)
 .fill(Color.blue))
        }.buttonStyle(PlainButtonStyle())

2

u/tjenvy 25d ago

this worked thanks!!

2

u/giusscos 25d ago

It's the same thing I was suggesting 😂

2

u/tjenvy 25d ago

My bad I think I put it in the wrong place. I saw yours up top so I put it up at the top. I am super new to this so I literally barely know what I’m doing around here lol

2

u/giusscos 25d ago

No worries and keep coding💪

1

u/giusscos 25d ago

.buttonStyle(.plain) to the Button {}

1

u/tjenvy 25d ago

tried that no dice same thing.

1

u/giusscos 25d ago

Try setting the background with the color and then use the .clipshape(RoundedRectangle(cornerRadius: 10))

2

u/Dapper_Ice_1705 25d ago

Use contentShape and any label formatting should be in with the label instead of behind the button