导航视图背景颜色 [英] Navigation View background Color
本文介绍了导航视图背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在我的 SwiftUi 列表上设置背景颜色,至于我在这里的帖子:
但实际上它是这样的:
struct ContentView: 查看 {var dm : 数据管理器初始化(dmi:数据管理器){self.dm = dmiUITableView.appearance().backgroundColor = UIColor.clearUITableViewCell.appearance().backgroundColor = .clear}var主体:一些视图{ZStack{RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all).覆盖(//导航视图{列表{ForEach(dm.vector, id: \.self) { item in文本(字符串(项目))}}//})}}}
解决方案
很简单.我不建议你这样做,你最好遵循apple ui设计推荐
struct ContentView: 查看 {在里面() {UITableView.appearance().backgroundColor = UIColor.clearUITableViewCell.appearance().backgroundColor = .clear}var主体:一些视图{导航视图{RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all).覆盖(列表{文本(阿尔法")NavigationLink(destination: Text("LINKED")) {文本(标签")}}.navigationBarTitle("表格"))}}}
I'm try to set a background color on my SwiftUi List, as for my post here: SwiftUI Background List color
I found a solution inserting the following code as init()
init() {
UITableView.appearance().backgroundColor = UIColor.clear
UITableViewCell.appearance().backgroundColor = .clear
}
my issue now is ... as soon I insert a Navigation Link the background color again became white.
how to set the color to .clear to the NavigationView? I have tried to .foregroundColor(.clear) but noting...
what I want is having a nav link working with no white background.. like this
but actually it does like this :
struct ContentView: View {
var dm : DataManager
init(dmi: DataManager) {
self.dm = dmi
UITableView.appearance().backgroundColor = UIColor.clear
UITableViewCell.appearance().backgroundColor = .clear
}
var body: some View {
ZStack{
RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all)
.overlay(
// NavigationView{
List{
ForEach(dm.vector, id: \.self) { item in
Text(String(item))
}
}
// }
)
}
}
}
解决方案
It is easy. I don't suggest you to do it, you better follow apple ui design recommendation
struct ContentView: View {
init() {
UITableView.appearance().backgroundColor = UIColor.clear
UITableViewCell.appearance().backgroundColor = .clear
}
var body: some View {
NavigationView {
RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all)
.overlay(
List{
Text("Alfa")
NavigationLink(destination: Text("LINKED")) {
Text("Label")
}
}.navigationBarTitle("Table")
)
}
}
}
这篇关于导航视图背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文