DEV Community

Maegan Wilson
Maegan Wilson

Posted on • Updated on • Originally published at Medium

Button Styles in SwiftUI

Button Styles in SwiftUI

This is a table explaining the different button styles in SwiftUI and which platform each Button Style is available on.

Button Style iOS watchOS iPad OS macOS
PlainButtonStyle
LinkButtonStyle
BorderedButtonStyle
BorderlessButtonStyle

How to use

Here is sample code of how to use a Button Style in SwiftUI.


Button(action: {
    print("plain")
}) {
    Text("Borderless button")
}.buttonStyle(BorderlessButtonStyle())

Enter fullscreen mode Exit fullscreen mode

In the GitHub repo, there is an Xcode project with each button style used.

Button Styles

This is a table explaining the different button styles in SwiftUI and which platform each Button Style is available on.

Button Style iOS watchOS iPad OS macOS
PlainButtonStyle
LinkButtonStyle
BorderedButtonStyle
BorderlessButtonStyle

How to use

Here is sample code of how to use a Button Style in SwiftUI.

Button(action: {
    print("plain")
}) {
    Text("Borderless button")
}.buttonStyle(BorderlessButtonStyle())
Enter fullscreen mode Exit fullscreen mode

In the GitHub repo, there is an Xcode project with each button style used.


If you enjoyed this post and want more, please consider subscribing to my Patreon and checking out my other posts!

If you don't like having more subscriptions, consider buying me a coffee by clicking the image below! Buy Me A Coffee



If you enjoy my posts, please consider sharing it or Buying me a Coffee!

Buy Me A Coffee

Top comments (4)

Collapse
 
hemaks123 profile image
hemaks123

Hi ,

I have doubt on how to get a button id inside the button action in swiftui? Is there any way to print the button id inside action?

Collapse
 
maeganwilson_ profile image
Maegan Wilson

What do you mean by button id? I don’t quite understand.

Collapse
 
hemaks123 profile image
hemaks123

Is it possible to access the button tag inside the button action in SwiftUI?

Collapse
 
hemaks123 profile image
hemaks123

In UIKit we can set a button tag and can access it inside the @IBAction method. The same thing I want to do with swiftui. Is it possible to access the button tag inside the button action in SwiftUI?