iosswiftbuttonswiftuiuikit

Is there a SwiftUI version of the UIKit UIButton.ButtonType.close?


Right now, I am in the process of converting from UIKit to SwiftUI. In UIKit, there is a native Close, X-Styled Button - UIButton.ButtonType.close, like shown below:

enter image description here

I wanted to find the equivalent of this in SwiftUI, if built in to SwiftUI already. It is understandable if Apple hasn't gotten around to building/converting this yet. I see this also in the Apple Maps App, which I believe is built in SwiftUI, like shown below (on the bottom right corner of the panel):

enter image description here

If there isn't a built in button styling, how would one go about creating a View for this close button, which would adapt to light and dark mode? Thank you so much!

Edit: In UIKIt's Storyboard Editor, here is what I am looking for:

enter image description here


Solution

  • SwiftUI does not use concept of "button type", instead you can construct it by yourself, like

    Button(action: {}) {
        Image(systemName: "xmark.circle.fill")   // << base !!
            .resizable()
            .frame(width: 32, height: 32) // << for demo
            .foregroundColor(.gray)
    }
    

    *with any other modifiers as you wish

    demo

    Xcode 13.4 / iOS 15.5