ButtonStyle & LabelStyle
Build branded, reusable control styles.
Style Controls, Not Instances
Restyling every button by hand gets tedious. A ButtonStyle defines one branded look you reuse across the whole app. 🎨
The ButtonStyle Protocol
Conform a struct to ButtonStyle and implement makeBody. It receives a configuration and returns the styled button.
struct PrimaryStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
}
}All lessons in this course
- Extracting Reusable Views
- Custom ViewModifiers
- ButtonStyle & LabelStyle
- ViewBuilder & Generic Containers