> 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/swiftui/view/swipe-actions.md).

# Swipe Actions

🚧 施工中

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

```swift
// Some code
struct AccountView: View {
    
    // view states
    @State var isDeleted = false
    
    // view body
    var body: some View {
        NavigationView {                        // navigation view
            List {                              // list
                Section {
                    // conditional view ⭐️
                    if !isDeleted {
                        Link(destination: URL(string: "https://apple.com")!) {
                            HStack {
                                Label("Apple", systemImage: "house")
                                Spacer()
                                Image(systemName: "link").tint(.secondary)
                            }
                        }
                        .swipeActions {    // swipe actions ⭐️
                            
                            // first action (default action?)
                            Button {
                                isDeleted = true
                            } label: {
                                // ⭐️ 雖然用 `Label`，但只會顯示圖示。
                                Label("Delete", systemImage: "trash")
                            }.tint(.red)    // override button color ⭐️
                            
                            // second action
                            Button {} label: {
                                Label("Pin", systemImage: "pin")
                            }.tint(.yellow)
                        }
                    }
                    
                    // Link
                    Link(destination: URL(string: "https://youtube.com")!) {
                        HStack {
                            Label { Text("YouTube") } icon: {
                                Image(systemName: "tv")
                                    .foregroundColor(.red)
                            }
                            Spacer()
                            Image(systemName: "link").tint(.secondary)
                        }
                    }
                }

            }
            .listStyle(.insetGrouped)           // list style
            .navigationTitle("Account")         // navigation title
        }
    }
}
```

{% endtab %}

{% tab title="📘 手冊" %}

* View
  * [Input and Events](https://developer.apple.com/documentation/swiftui/view-input-and-events)
    * [.swipeActions(edge:allowsFullSwipe:content:)](https://developer.apple.com/documentation/swiftui/view/swipeactions\(edge:allowsfullswipe:content:\))
      {% endtab %}

{% tab title="📗 參考" %}

* Design+Code - [States and Swipe Actions](https://designcode.io/swiftui-ios15-states-swipe-actions)
* Hacking with Swift - [How to add custom swipe action buttons to a List row](https://www.hackingwithswift.com/quick-start/swiftui/how-to-add-custom-swipe-action-buttons-to-a-list-row)
* Use Your Loaf - [SwiftUI Swipe Actions](https://useyourloaf.com/blog/swiftui-swipe-actions/)
  {% endtab %}
  {% endtabs %}
