Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI button action with no text content

Tags:

swiftui

I have two buttons next to each other. One is for starting a recording, one is for playing. When I click the play button, I see "play clicked" logged. When I click the record button, nothing happens. When I add a letter to the record button text, it's logged just fine.

Why can't I use a button with empty text in SwiftUI?

Button(action: {
    print("record clicked")
}) {
    Text("")
}
.frame(width: 55, height: 55)
.background(Color.red)
.cornerRadius(9999)

Button(action: {
    print("play clicked")
}) {
    Image(systemName: "play")
        .foregroundColor(.white)
        .font(.system(size: 30))
}
.frame(width: 55, height: 55)
.background(Color.green)
.cornerRadius(9999)
like image 520
damd Avatar asked Nov 16 '25 04:11

damd


1 Answers

They determine tappable area for button by label content, but it is almost zero for empty text, so just make it remarkable, like

Button(action: {
    print("record clicked")
}) {
    Text("")
        .padding()     // << this !!
}

Tested as worked with Xcode 13 / iOS 15

like image 155
Asperi Avatar answered Nov 18 '25 21:11

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!