Search code examples
swiftswiftuiwidgetios16lockscreenwidget

How do you get rid of the background color in iOS lock screen widget?


Using the following code:

    var body: some View {
        switch widgetFamily {
        case .accessoryInline:
            inlineAccessory
        case .accessoryRectangular:
            rectangularAccessory
        case .systemLarge,.systemMedium:
            homeScreenWidget
        default:
            EmptyView()
        }
    }

    var rectangularAccessory: some View {
        ViewThatFits {
            VStack (alignment: .leading){
                Text("\(entry.listVM.datedList.results.displayName)")
                    .font(.headline)
                
                Text("#1: \(entry.listVM.datedList.results.books[0].title)")
                    .font(.body)
            }
        }
    }

I get a lock screen widget with a gray background.

enter image description here

I have tried adding AccessoryWidgetBackground(), .backgoundStyle(.clear) and everything else I could think of, but I can never get rid of that gray background. I have changed the wallpaper and still it remains.

Any ideas?


Solution

  • remove WidgetBackground in StaticConfiguration

    .background(Color("WidgetBackground")) <<<< remove