Create a Custom List in SwiftUI

Create a Custom List in SwiftUI

In this tutorial, we are going to create a custom list with two action buttons that will appear when you swipe a row to the left. We are going to start with one side button. It will be a delete button. Then we can add a second button to show how to add more buttons to the row.

In this tutorial, we are going to create a custom list with two action buttons that will appear when you swipe a row to the left. We are going to start with one side button. It will be a delete button. Then we can add a second button to show how to add more buttons to the row.

Start a new iOS 14 project, then follow along.

Constants and Variables

Create a new struct of type View and declare the following variables:

struct RowContent : View {
        let text : String
        let index : Int
        let width : CGFloat = 60
        @Binding var indices : [Int]
        @State var offset = CGSize.zero
        @State var scale : CGFloat = 0.5

        var body : some View {
        // UI Elements
        }
    }
  • Text: Stores our row’s content.
  • index: The row’s index. Used to delete/hide a row.
  • width: The width of all the side buttons. Used to know how much to swipe to the left.
  • indices: Binding array variable that stores the deleted/hidden rows’ indices.
  • offset: Float variable used to move a row to the left when a swipe motion occurs.
  • scale: Used to animate the scale of the side buttons when they appear.

mobile swift programming swiftui ios

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

SwiftUI Grids in iOS 14

SwiftUI was announced at WWDC 2019 and it paved a way for declarative programming for building interfaces. SwiftUI Grid comes in two different flavours, which includes LazyVGrid and LazyHGrid. As the name suggest, LazyVGrid is a Grid that flows in vertical direction and the LazyHGrid flows in horizontal direction

How to Build a Timer using Swift and SwiftUI

A great place to start building with SwiftUI

Understanding Grids in SwiftUI for iOS 14

SwiftUI was announced at WWDC 2019 and it paved a way for declarative programming for building interfaces. SwiftUI Grid comes in two different flavours, which includes LazyVGrid and LazyHGrid. As the name suggest, LazyVGrid is a Grid that flows in vertical direction and the LazyHGrid flows in horizontal direction.

SwiftUI’s GroupBox, OutlineGroup, and DisclosureGroup in iOS 14

SwiftUI was inevitably going to see big changes this year, and I'm really excited to experiment with them all – text views, color pickers, progress

Want More From ColorPicker in iOS 14? Create 1500+ SwiftUI Pickers of Your Own

Make custom colour pickers and reuse them in any project with Swift Package Manager