Skip to content

Instantly share code, notes, and snippets.

@enomoto
Created September 20, 2022 00:26
Show Gist options
  • Save enomoto/9b9fa9f41f1b45beb81b6c8f9d29d06d to your computer and use it in GitHub Desktop.
Save enomoto/9b9fa9f41f1b45beb81b6c8f9d29d06d to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
globeLabel
.padding()
}
}
private var globeLabel: some View {
Label("Hello, world!", systemImage: "globe")
.labelStyle(.mainLabelStyle) // Applying custom LabelStyle
}
}
extension LabelStyle where Self == MainLabelStyle {
static var mainLabelStyle: MainLabelStyle {
.init()
}
}
struct MainLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.icon
.imageScale(.large)
.foregroundColor(.accentColor)
configuration.title
.fontWeight(.bold)
}
}
}
@enomoto
Copy link
Author

enomoto commented Sep 20, 2022

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