Is it possible to transform that text of a label in a SwiftUI button to uppercase using a style?
struct UppercaseButtonStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.makeUppercase() // ?
}
}
2
Answers
usage:
The
textCase
modifier will work directly on your button, e.g.:However, if you want to wrap this up in a style, it’s better to use a
PrimitiveButtonStyle
, as this comes with aConfiguration
object that can be passed into theButton
initializer.This means that you don’t need to worry about any other type of configuration on the button, and your style should be able to play nicely with others, e.g.: