Created
September 20, 2022 00:26
-
-
Save enomoto/9b9fa9f41f1b45beb81b6c8f9d29d06d to your computer and use it in GitHub Desktop.
Sample for LabelStyle https://developer.apple.com/documentation/swiftui/labelstyle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Author
enomoto
commented
Sep 20, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment