I have a view in SwiftUI and no work a change backgroud color metod. My main code is:
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)
}
}
}
The generic element of my list is a custom element, and the code is (store in another file class):
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)
}
but, unfortunately the background color remains "white" and is not changed. The desidered color is : Color(red: 0.17, green: 0.24, blue: 0.31)
this is a runtime result: simulator
Help me please!
