swift - 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
解决方案
你需要把所有的都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)
}
}
)
}
}
}
}
否则,它们会因为被禁用而变暗。
推荐阅读
- python - Pexpect 进程死亡而不是发送命令
- javascript - Instafeed 按标签或帖子排除
- python - 禁用 QWizardPage 的下一个按钮的默认焦点,并让自定义 QPushButton 由“输入”触发
- postgresql - PostgreSQL:使用参数创建视图名称
- kubernetes - Kubernetes Headless Service 解析为多接口 Pod 的特定接口
- android - 如何用 Kotlin 的协程替换回调
- php - barryvdh/laravel-snappy - 退出状态代码 '1' 表示出了点问题:\nstderr: \"Loading pages (1/6)\r\n
- kotlin - Kotlin 内在的 `areEqual` 方法的目的是什么?
- php - php_value display_errors 0 导致 .htaccess 中出现 500 错误
- python - 在循环中更新一行,然后在下一次迭代中使用更新的值