If I have this ViewModifier.
struct AppFont: ViewModifier {
var size: Int?
func body(content: Content) -> some View {
content.font(Font.custom("Futura", size: CGFloat(size ?? 15)))
}
}
From that I create an extension one for Text and one for Textfield
extension Text {
func customFont(size : Int) -> some View {
return ModifiedContent(content: self, modifier: AppFont(size: size))
}
}
extension TextField {
func customFont(size : Int) -> some View {
return ModifiedContent(content: self, modifier: AppFont(size: size))
}
}
How can I add this extension to Text, Textfield and Button without repeating the code? So I could use Text("hello").customFont() TextField(...).customFont() or Button().customFont()