# view modifier (template)

[swift](../../swift) ⟩ [custom](..) ⟩ [snippets]() ⟩ view modifier (template)

{% tabs %}
{% tab title="💾 程式" %}
```swift
import SwiftUI

// 1. (internal) view modifier
struct MyViewModifier: ViewModifier {
    
    // ⭐️ 2. new states (optional)
    @State private var blur = true              
    
    // body(content:) - ViewModifier requirement
    func body(content: Content) -> some View {
        // ⭐️ 3. modify input `content`
        content
            .blur(radius: blur ? 20 : 0)
            .clipped()
            .onTapGesture { 
                withAnimation {
                    self.blur.toggle()
                }
            }
    }
}

// ⭐️ 4. public helper
extension View {
    public func myModifier() -> some View { 
        modifier(MyViewModifier()) 
    }
}
```
{% endtab %}

{% tab title="👥 相關" %}
* [modifier](../../swiftui/view/modifier "mention")
* [viewmodifier](../../swiftui/view/modifier/viewmodifier "mention")
{% endtab %}

{% tab title="💈範例" %}
* [nsfw](../../swiftui/view/modifier/examples/nsfw "mention")
{% endtab %}
{% endtabs %}
