在SwiftUI中关闭按钮高亮显示

4

我该如何在SwiftUI中关闭按钮高亮显示,当它被点击或按下时。

这是我的代码:

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)))
    }

如果我移除按钮并将 onTapGesture 添加到 SearchUserRow 上,那么只有内容部分是可选择的,而不是整个行。

尝试直接在需要保持颜色的地方使用.foregroundColor(.primary) - Mojtaba Hosseini
@kontiki 尝试了相同的方法,但它并没有起作用。 - SwiftiSwift
1个回答

3

可以试试这个,它对我有用,但由于我没有 SearchUserRow() 代码,所以无法完全尝试:

SearchUserRow(user: user).foregroundColor(.primary)
    .contentShape(Rectangle())
    .onTapGesture { ... }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接