I am currently trying to update my apps widgets to support iOS 18’s tinted Home Screen customization option. For that I am trying to apply .widgetAccentable() where needed. However, I encounter an issue when it comes to Swift Charts.
My code looks currently something like this:
Chart {
ForEach(data, id: .id) { day in
BarMark(
x: .value("###", day.date, unit: .day),
y: .value("###", day.value)
)
.cornerRadius(10.0)
.foregroundStyle(Color.blue.gradient)
.alignsMarkStylesWithPlotArea()
.annotation {
Text(day.value.description)
.font(.subheadline)
}
}
}
.widgetAccentable()
.chartYAxis(.hidden)
.chartXAxis {
AxisMarks(values: .stride(by: .day)) { value in
AxisValueLabel(format: Date.FormatStyle().weekday(.short), centered: true)
}
}
The problem is that I can only apply .widgetAccentable() to the whole chart. This will tint everything (bar marks, labels, axis, …) in the tint color.
What I want to achieve is to tint only the bar marks but not the labels and everything else … those should stay in black/white monochrome colors.
Is there any way to make that work?