I have a horizontal scrollView which shows a bunch of images from a dynamic image array. When the total content width is greater than the screen width everything is fine. However if say there is only one image in the array, it will be leading aligned which is the default behavior.
I want the content to be centered when the total content width is less than screen width and not sure how to achieve that:
ScrollView(.horizontal) {
HStack {
ForEach(images.indices, id: \.self) { index in
let image = images[index] {
Image(uiImage(uiImage: image))
}
}
}
.frame(height: 200)
}
So in this case if there is only one image it is leading aligned but I want it to be centered until the content fills the screen then for it to scroll. I don't mind bounce or no bounce until it fills screen.