I am using a "Slider" in my WatchOS interface, built with SwiftUI.
Since the Slider is contained inside another container, I really need the background of the Slider to be fully transparent (Color.clear
).
I have tried to use the .background(Color.clear)
modifier and .buttonStyle(PlainButtonStyle())
, both made no difference to the default behaviour of the Slider, there is always the default semi-transparent background.
Is there any way to get rid of that default background of the Slider component on WatchOS?
import SwiftUI
struct CustomSlider: View {
@State var value: Double = 2.0
var body: some View {
VStack {
Text("Adjust value")
Slider(
value: $value,
in: 0...3,
step: 1,
minimumValueLabel: Text("-"),
maximumValueLabel: Text("+")
) {}
.buttonStyle(PlainButtonStyle())
.background(Color.clear)
.accentColor(.green)
Text("VALUE")
.foregroundColor(.white)
}
.padding()
.background(Color(red: 0.1, green: 0.2, blue: 0.3, opacity: 1.0))
.cornerRadius(10.0)
}
}
struct CustomSlider_Previews: PreviewProvider {
static var previews: some View {
CustomSlider()
}
}