首页 > 解决方案 > NavigationLink 文本模糊 swiftui

问题描述

我有一个部分,里面有一些项目,我希望这些项目触发单独的视图我遇到的问题是我的 NavigationLink 按钮上的颜色对比度模糊,但如果我使用常规按钮,它就会出现正确。这是我的代码,这是显示的图像

VStack {
    Form {
        Section {
            Button(action: {}, label: {
                HStack(spacing: 2) {
                    Image("logouticon")
                        .frame(height: 40)
                        .frame(width: 40)
                        .foregroundColor(.black)
                    Text("Logout")
                        .foregroundColor(.red)
                        .font(.system(size: 14, weight: .regular, design: .default))
                        
                        .multilineTextAlignment(.leading)
                        .foregroundColor(.black)
                    
                }.background(Color.clear)
            })
            NavigationLink(
                destination: EmptyView(),
                label: {
                    HStack(spacing: 2) {
                        Image("logouticon")
                            .frame(height: 40)
                            .frame(width: 40)
                            .foregroundColor(.black)
                        Text("Logout")
                            .foregroundColor(.red)
                            .font(.system(size: 14, weight: .regular, design: .default))
                            
                            .multilineTextAlignment(.leading)
                            .foregroundColor(.black)
                        
                    }
                }
            )
        }
    }
}

下图是 NavigationLink,上图是 Button

在此处输入图像描述

标签: swiftswiftui

解决方案


你需要把所有的都NavigationLinks放在NavigationView这样的地方:

    NavigationView {
        VStack {
            Form {
                Section {
                    Button(action: {}, label: {
                        HStack(spacing: 2) {
                            Image("logouticon")
                                .frame(height: 40)
                                .frame(width: 40)
                                .foregroundColor(.black)
                            Text("Logout")
                                .foregroundColor(.red)
                                .font(.system(size: 14, weight: .regular, design: .default))
                                
                                .multilineTextAlignment(.leading)
                                .foregroundColor(.black)
                            
                        }.background(Color.clear)
                    })
                    NavigationLink(
                        destination: EmptyView(),
                        label: {
                            HStack(spacing: 2) {
                                Image("logouticon")
                                    .frame(height: 40)
                                    .frame(width: 40)
                                    .foregroundColor(.black)
                                Text("Logout")
                                    .foregroundColor(.red)
                                    .font(.system(size: 14, weight: .regular, design: .default))
                                    
                                    .multilineTextAlignment(.leading)
                                    .foregroundColor(.black)
                                
                            }
                        }
                    )
                }
            }
        }
    }

否则,它们会因为被禁用而变暗。


推荐阅读