I'm trying to design a mixing desk for an iPad app using SwiftUI. I have an image for the background of the fader and will be using a slider stacked on top of it to change the volume. I have a View called faderView() which contains the image and the slider.
struct FaderView: View {
@State var sliderValue: CGFloat = 0
var body: some View {
ZStack{
//FaderBackground()
Image("FaderBackground")
.resizable()
.scaledToFit()
.cornerRadius(10)
.padding()
//Faderslider()
GeometryReader { geo in
HStack(alignment: .center) {
Slider(
value: $sliderValue,
in: 0...127,
step: 1.0
)
.frame(width: geo.size.height * 0.84)
.rotationEffect(.degrees(-90.0), anchor: .center)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
}
}
This results in the following View which is exactly what I want (for now)
If I then use a HStack to make multiple of these, the slider now moves to the right and I don't understand why. The code for just one is:
struct MixerView: View {
var body: some View {
HStack{
FaderView()
}
}
}
struct MixerView: View {
var body: some View {
HStack{
FaderView()
FaderView()
}
}
}
Any help with this would be greatly appreciated.