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
}
}
}
View
Last updated
Was this helpful?