Skip to content

ThemeModifier

ppraveentr edited this page Apr 2, 2023 · 3 revisions

ThemeModifier

A modifier that you apply to a view or another view modifier, producing a different version of the original value.

public struct ThemeModifier: ViewModifier 

The example below combines several modifiers to create a new modifier that you can use to create blue text in 'title' font:

struct ContentView: View {
    var body: some View {
        Text("Downtown Bus")
            .font(.title)
            .foregroundColor(Color.blue)
    }
}

Instead, you can then apply the theme style to any view, similar to this:

Text("Downtown Bus")
    .style("styleName")

This shows the Text View: "Downtown Bus", using custom a modifier, renders the text in blue text with "Title" font.

Inheritance

ViewModifier

Methods

body(content:)

public func body(content: Content) -> some View