Rasul
Rasul

Reputation: 792

Hide arrow and highlighting when press on NavigationLink

I have NavigationLink in List, and when I click to it, it highlights item. And also arrow shows at the right corner

NavigationLink(destination: ItemsListView()) {                    
                Text("Show all (\(body.count))")
                                 .font(.body)
                                 .foregroundColor(Color.red)
}

How can hide the arrow in the right corner, and also disable highlighting?

Upvotes: 1

Views: 1933

Answers (2)

Adeyemi Seun
Adeyemi Seun

Reputation: 111

 .opacity(0.0) // just add this to the navigationLink

 NavigationLink(destination: Text("\(element)")) {Text("\(element)")} .opacity(0.0)

Upvotes: -1

Andrew
Andrew

Reputation: 28539

You can set the selection style of the cell by doing the following.

  • Create an init function for the struct that contains your List
  • Get the appearance for UITableViewCell
  • Set the selectionStyle to be .none

Here is some example code:

struct ContentView: View {

    init() {
        let appearance = UITableViewCell.appearance()
        appearance.selectionStyle = .none
        // appearance.accessoryType = .none
    }

    var body: some View {
        NavigationView {

            List(0..<5, id: \.self) { element in

                NavigationLink(destination: Text("\(element)")) {

                    Text("\(element)")

                }

            }
        }
    }
}

It should be possible to hide the accessoryType of the cell by setting it to .none as well (see the commented out code above) but it doesn't seem possible at this time.

Upvotes: 2

Related Questions