I'm trying to implement a ScrollView using SwiftUI that contains an HStack and ForEach() of calendar objects to scroll through back and forth to select a date to mimic below:
The array of dates would be say 30 days in the past of today's date and 30 days in the future. When I initialize the ScrollView, it always starts on the 30th day in the past (Array index 0) but how could I offset the scroll of the ScrollView to where today's date is centered in the view? I've tried using .content.offset(x: offset)
but it physically offsets the location of the scroll in the view, not the amount scrolled.
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .center, spacing: self.spacing) {
ForEach(self.dateArray, id: \.self) { date in
CalendarObject(date: date)
}
}
}
.content.offset(x: -self.offset, y: 0)