4

how can i turn off the button highlighting in SwiftUI, when its tapped or pressed.

Here's my code:

ScrollView {
        ForEach(searchManager.resultUsers) { user in
            Button(action: {
                self.showProfile = true
                self.user = user
            }) {
                SearchUserRow(user: user)
                    .foregroundColor(.primary)
            }
        }
    }.sheet(isPresented: $showProfile) {
        ProfileView(profileUser: self.user)
            .environmentObject(ProfileManager(userID: self.user.userID, fetchingMode: .user(mode: .tweets)))
    }

if i remove the button and add onTapGesture to SearchUserRow not the complete row is selectable, only the content part.

2
  • Try using .foregroundColor(.primary) directly on what you want to keep the color. Commented Aug 5, 2019 at 13:14
  • @kontiki tried the same but it doesn't work Commented Aug 5, 2019 at 14:59

1 Answer 1

4

Try this one, it works for me, but since I don't have the SearchUserRow() code, I cannot fully try it myself:

SearchUserRow(user: user).foregroundColor(.primary)
    .contentShape(Rectangle())
    .onTapGesture { ... }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.