> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/custom/snippets/view-modifier-template.md).

# view modifier (template)

[swift](/ios/swift.md) ⟩ [custom](/ios/custom.md) ⟩ [snippets](/ios/custom/snippets.md) ⟩ 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="👥 相關" %}

* [view modifier](/ios/swiftui/view/modifier.md)
* [ViewModifier](/ios/swiftui/view/modifier/viewmodifier.md)
  {% endtab %}

{% tab title="💈範例" %}

* [.nsfw()](/ios/swiftui/view/modifier/examples/nsfw.md)
  {% endtab %}
  {% endtabs %}
