Created
October 22, 2020 12:32
-
-
Save davidsteppenbeck/6d417427651776aee1214ae30a8240c7 to your computer and use it in GitHub Desktop.
A SwiftUI label style for icons with dynamic colored backgrounds.
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
/// Sets a colored rounded rectangle behind the icon. | |
struct ColorIconLabelStyle: LabelStyle { | |
/// The color behind the icon. | |
var color: Color | |
/// The corner radius of the color behind the icon. | |
@ScaledMetric private var radius: CGFloat = 5 | |
func makeBody(configuration: Configuration) -> some View { | |
Label { | |
configuration.title | |
} icon: { | |
ZStack { | |
RoundedRectangle(cornerRadius: radius) | |
.foregroundColor(color) | |
.aspectRatio(1.0, contentMode: .fit) | |
configuration | |
.icon | |
.foregroundColor(.white) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment