swift - Why the button is not highlighted when is pressed? - Stack Overflow

admin2025-04-25  2

I would like to see some highlight when the button is pressed, but is not there. I need to press for minimum 1 second to see the highlight on the button. What's wrong here ?

This is ContactsView:

        ZStack {
            Color.backgroundColor.ignoresSafeArea()
            VStack(spacing: .zero) {
                HStack {
                    Image(uiImage: UIImage(data: contactImage ?? Data()) ?? UIImage())
                        .resizable()
                        .scaledToFill()
                        .frame(width: 50, height: 50)
                        .clipShape(Circle())
                        .overlay(Circle().stroke(Color.white, lineWidth: 4)) //
                        .padding(.leading, .large)
                    
                    Text(contactName ?? "")
                        .foregroundStyle(.white)
                        .fontWeight(.heavy)
                    
                    Spacer()
                    
                    Button {
                        print("Share code")
                    } label: {
                        Text("Add friend")
                        .padding(.medium)
                        .background(Color.white)
                        .cornerRadius(16)
                        .padding(.horizontal, .large)
                        .foregroundColor(.black)
                    }
                }
            }
            .frame(maxWidth: .infinity, alignment: .leading)
        }

This is how is used:

        ScrollView {
            ForEach(viewModel.getContacts, id: \.id) { contact in
                VStack(spacing: .zero) {
                    ContactsView(contactImage: contact.thumbnail ?? Data() , contactName: contact.fullName ?? "")
                }
                .padding(.vertical, .large)
            }
        }

转载请注明原文地址:http://anycun.com/QandA/1745534082a90877.html