Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created December 22, 2023 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/9c9e593b5b00cb89b4f3b953de9b0ff6 to your computer and use it in GitHub Desktop.
Save shaps80/9c9e593b5b00cb89b4f3b953de9b0ff6 to your computer and use it in GitHub Desktop.
Provides a button style that can be provided inline, useful during prototyping or for simply 'removing' any styling.
import SwiftUI
public extension View {
func buttonStyle(_ style: @escaping (InlineButtonStyle.Configuration) -> some View) -> some View {
buttonStyle(InlineButtonStyle(style: style))
}
}
public struct InlineButtonStyle: ButtonStyle {
@ViewBuilder let style: (Configuration) -> any View
public func makeBody(configuration: Configuration) -> some View {
AnyView(style(configuration))
}
}
@shaps80
Copy link
Author

shaps80 commented Dec 22, 2023

Example:

struct ContentView: View {
    var body: some View {
        Button { } label: { 
            Text("Done") 
        }
        .buttonStyle { configuration in
            configuration.label
                .font(.footnote)
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment