🔰Swipe Actions
🚧 施工中
// 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
}
}
}
Design+Code - States and Swipe Actions
Hacking with Swift - How to add custom swipe action buttons to a List row
Use Your Loaf - SwiftUI Swipe Actions
Last updated