Reputation: 21
I'm building a to-do app in Swift as a practice project, and would like to make it so that when the user swipes from left to right on a task in the list, my "completed
" boolean in the task becomes true
. Similar how in the native Mail app, swiping right on an email marks it read.
I came across the onDelete()
function provided by Apple that handles right to left swipes, but as far as I can tell there's no code for left to right swipes. I think that makes it ok to implement a left to right swipe, but I can't find any examples of how to do so in SwiftUI. I think this question was asked once on Stack Overflow here, but the answer only pertained to deleting and moving.
Upvotes: 1
Views: 2144
Reputation: 119302
You can define any number of actions with .swipeActionis
modifier for either leading
, or trailing
side of the cell with the given view as the label
and give them a tint
color like:
Upvotes: 3
Reputation: 182
that called gestures and for swipe gesture you can see the documentation here - https://developer.apple.com/documentation/uikit/uiswipegesturerecognizer
and if you don't want to make it from scratch then you can use library for it and the kind of functionality you want go for this library SwipeCellKit
here is link https://cocoapods.org/pods/SwipeCellKit with this you can easily make the kind of functionality you want.
Upvotes: 1