The settings options in my app are styled with an icon on a solid colour background and a text label next to them, similar to the items in Apple's iOS Settings app:
HStack(alignment: .center, spacing: 0) {
Image(...)
.foregroundColor(.white)
.frame(width: 28, height: 28, alignment: .center)
.background(
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(Color.blue)) // Color may be a property instead, simplified here.
.accessibility(hidden: true)
Text(title)
.font(.system(
size: 16,
weight: .medium,
design: .rounded))
.padding(.leading)
}
However, I've noticed that the background color (SwiftUI Color) for my icon views change when the system 'Increase Contrast' accessibility option is enabled, whereas the background colour of Apple's Settings icons do not. As an example, Color.orange looks more like a red color when 'Increase Contrast' is enabled.
I'd therefore like to ignore the current color scheme's contrast setting (ColorSchemeContrast environment value) if it's set to .increased, just for the background colour of my icon view.
Unfortunately, using the environment modifier gives an error, as .colorSchemeContrast is not a writable property:
.environment(\.colorSchemeContrast, .standard). This is similarly documented by Apple: "Your app cannot override the user’s choice.".
I'm only trying to avoid specific small areas of colour changing when contrast is increased, as Apple themselves do, so I can only assume there should be some way of achieving this.
Is there any other way to work around this issue?