0

I'm developing a camera application with SwiftUI and I need to create a component similar to this one

target

I have the next code

ScrollViewReader { proxy in
                        ScrollView(.horizontal) {
                            HStack(alignment: .center, spacing: 10) {
                                Button {
                                    if model.mediaType == .photo {
                                        model.mediaType = .video
                                        proxy.scrollTo(0)
                                    }
                                } label: {
                                    Text("Video")
                                        .foregroundColor(model.mediaType == .video ? .yellow : .white)
                                }
                                
                                Button {
                                    if model.mediaType == .video {
                                        model.mediaType = .photo
                                        proxy.scrollTo(1)
                                    }
                                } label: {
                                    Text("Photo")
                                        .foregroundColor(model.mediaType == .photo ? .yellow : .white)
                                }
                            }
                            .frame(alignment: .center)
                        }
                    }

But I'm having this result. current

How can I center the content of the ScrollView and reach the mentioned target?

Dani Garcia
  • 464
  • 1
  • 6
  • 18
  • Did you try to use padding at leading for first element of your content(in your case its video)? For making is use device width and set up padding for leading. – Namra Parmar Nov 01 '22 at 07:57

0 Answers0