0

I have a settings view and I want to change the entire view background color. Using Color(red: 1.000, green: 0.867, blue: 0.525).ignoresSafeArea() in a ZStack worked for my other views but not for this one. I also tried the background modifier, but it didn't work either. Can you help me find out how I can change the background color of the whole view?

var body: some View {
    ZStack {
        /// change the background color
        Color(red: 1.000, green: 0.867, blue: 0.525).ignoresSafeArea()
        
        List {
            Text("Settings")
                .font(.largeTitle)
                .padding(.bottom, 8)
            
            Section(header: Text("Notifications")) {
                HStack {
                    Toggle("Daily Reminder", isOn: $dailyReminderEnabled).onChange(of: dailyReminderEnabled, perform: {_ in configureNotification()})
                    DatePicker(
                        "",
                        selection: $dailyReminderTime,
                        displayedComponents: .hourAndMinute
                    )
                    .disabled(dailyReminderEnabled == false)
                    /// .onChange(of:perform:) is part of the View protocol, so you can use it on any view.
                    .onChange(of: dailyReminderTime, perform: { newValue in
                        /// This copies the number of seconds since the midnight of Jan 1, 1970, as a double value, into the shadow property for the App Storage.
                        dailyReminderTimeShadow = newValue.timeIntervalSince1970
                        configureNotification()})
                    .onAppear {
                        /// With it, every time the Section is displayed, the value stored in the shadow property is converted to a date and stored into dailyReminderTime.
                        dailyReminderTime = Date(timeIntervalSince1970: dailyReminderTimeShadow)
                    }
                }
            }
        }
    }
}

Settings view

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Murad
  • 104
  • 1
  • 1
  • 10
  • Does this answer your question? https://stackoverflow.com/questions/56517904/how-do-i-modify-the-background-color-of-a-list-in-swiftui – jnpdx Apr 09 '23 at 14:05
  • I tried the other things on that page but didn't notice ".scrollContentBackground(.hidden)" modifier. The background modifier works with that modifier together. Thank you. – Murad Apr 09 '23 at 14:13

0 Answers0