Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created December 22, 2023 10:01
Show Gist options
  • Select an option

  • Save shaps80/9c9e593b5b00cb89b4f3b953de9b0ff6 to your computer and use it in GitHub Desktop.

Select an option

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

shaps80 commented Dec 22, 2023

Copy link
Copy Markdown
Author

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