Sutton
Sutton

Reputation: 77

Editing default NavigationLink format in list cell - SwiftUI

I'm trying to get rid of the chevron that automatically accompanies the NavigationLink in a List view cell. Right now, I'm trying to cover up up the NavigationLink as Timo suggested, but it's not working. Here is the code:

import SwiftUI

struct ContentView: View {
    
    var notesLink: some View {
        NavigationLink(destination: NotesView()) {
            EmptyView()
        }
        .opacity(0.0)
        Text("Notes")
    }
    
    var body: some View {
        NavigationView {
            List {
                ZStack {
                    HStack {
                        Text("1")
                        
                        Spacer()
                    }
                                            
                    HStack {
                        Spacer()
                        
                        Text("2")
                            .multilineTextAlignment(.center)
                            .frame(
                                alignment: .center
                            )
                        
                        Spacer()
                    }
                    
                    HStack {
                        Spacer()
                        
                        notesLink
                            .fixedSize()
                    }
                }
            }
        }
    }
}

Upvotes: 0

Views: 87

Answers (1)

Timo
Timo

Reputation: 187

If you don't need the functions of a list, you could use a ScrollView(_:). Then there will be no arrows.

If you want the functions of a list, the most common approach to remove the chevron is to use a ZStack and covering the NavigationLink:

ZStack {
     NavigationLink(destination: DestinationView()) { 
         EmptyView()
     }
     .opacity(0.0)
     CardView() //This will be the view that you want to display to the user
}

Upvotes: 1

Related Questions