top of page

import SwiftUI

​

struct List_iOS15: View {
    
    let fruitList = [
        "Apple", "Pineapple",
        "Banana", "Blue Berry",
        "Mango", "Grape",
        "Dragon Fruit", "Watermelon",
        "Strawberry", "Melon"
    ]
    
    var body: some View {
        ZStack {
            
           
//background color
            Color.pink.edgesIgnoringSafeArea(.all)
            
           
//a SwiftUI collection view
            //similar to the UITableView

            List(fruitList.indices, id: \.self) {
                Text(fruitList[$0])
                   
//customizes the row looks
                    .listRowBackground(
                        $0 % 2 == 0 ? Color.yellow : Color.green
                    )
           
        //removes the separator line
                    .listRowSeparatorTint(.clear)
                    
            }
           
//sets the list to take up only the needed spaces
            .scrollContentBackground(.hidden)
            .listStyle(.grouped)
            
        }
    }
    
}

 

Simulator Screen Shot - iPhone 13 - 2022-11-25 at 11.27.47_iphone13midnight_portrait.png

IOS 15+ provides the features that every SwiftUI developer always dreams of. Customizes List() in SwiftUI has always been difficult due to the lack of features, and you must always write mixed codes of SwiftUI and UIKit.

© 2022 by Samreth Kem

bottom of page