【发布时间】:2021-03-11 16:00:22
【问题描述】:
我在 SwiftUI 中有一个视图,但没有改变背景颜色的方法。我的主要代码是:
var body: some View {
ZStack {
Color(red: 0.17, green: 0.24, blue: 0.31)
.edgesIgnoringSafeArea(.all)
VStack{
NavigationLink(destination: WelcomeView(),isActive: $isShowWelcomeView){}
List(Modules.Modules) { module in
NavigationLink(destination: ModuleView(moduleName: module.name)){
ModuleRow(mod: module)
}
}
.navigationBarItems(trailing:
Button(action: {logout()}) {
Text("Logout")
})
.navigationBarTitle("CORSO")
.navigationBarBackButtonHidden(true)
}
}
}
我列表的通用元素是自定义元素,代码是(存储在另一个文件类中):
var body: some View {
ZStack {
Color(red: 0.17, green: 0.24, blue: 0.31)
.cornerRadius(12)
HStack {
VStack(alignment: .leading, spacing: 8) {
Text(mod.name)
.font(.title)
.fixedSize(horizontal: false, vertical: true)
.foregroundColor(.yellow)
Text(mod.summary)
.font(.caption)
.foregroundColor(.yellow)
}
Spacer()
Image(systemName: mod.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50, height: 50, alignment: .center)
.padding()
.foregroundColor(.yellow)
}
.padding()
.background(Color(red: 0.17, green: 0.24, blue: 0.31))
.listRowBackground(Color(red: 0.17, green: 0.24, blue: 0.31))
}
.fixedSize(horizontal: false, vertical: true)
.shadow(color: Color.black.opacity(0.2), radius: 5, x: 0, y: 2)
}
但是,不幸的是,背景颜色仍然是“白色”并且没有改变。想要的颜色是:Color(red: 0.17, green: 0.24, blue: 0.31)
这是一个运行时结果: simulator
请帮帮我!
【问题讨论】: