1

I have the following:

It shows just 1 image if 1 is available or if more than one image is there, it creates a HStack which should be scrollable to show all images:

 ScrollView {
        VStack (alignment: .leading) {
            if userData.profileURL1 != nil {
                ScrollView(.horizontal, showsIndicators: false) {
                    HStack {
                        URLImage(URL(string: userData.profileURL)!, placeholder: Image(systemName: "circle"),
                         content:  {
                            $0.image
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: (UIScreen.main.bounds.width - 33),height: 500)
                            }
                        )
                        .cornerRadius(12)
                        .padding([.leading,.trailing])
                        URLImage(URL(string: userData.profileURL1!)!, placeholder: Image(systemName: "circle"),
                         content:  {
                            $0.image
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: (UIScreen.main.bounds.width - 33),height: 500)
                            }
                        )
                        .cornerRadius(12)
                        .padding([.leading,.trailing])
                        if userData.profileURL2 != nil {
                            URLImage(URL(string: userData.profileURL2!)!, placeholder: Image(systemName: "circle"),
                             content:  {
                                $0.image
                                    .resizable()
                                    .aspectRatio(contentMode: .fill)
                                    .frame(width: (UIScreen.main.bounds.width - 33),height: 500)
                                }
                            )
                            .cornerRadius(12)
                            .padding([.leading,.trailing])
                        }
                    }
                }
            } else {
                URLImage(URL(string: userData.profileURL)!, placeholder: Image(systemName: "circle"),
                 content:  {
                    $0.image
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        .frame(width: (UIScreen.main.bounds.width - 33),height: 500)
                    }
                )
                .cornerRadius(12)
                .padding([.leading,.trailing])
            }
       }
}

The logic works and it displays multiple images if more than one are there, but doesn't show them correctly, the height of the images is not being applied from what I can tell:

enter image description here

enter image description here

The images are scrolling to show the other but the height is all messed up. But when only 1 image is present (else) then the image shows fine, full height and everything.

1
  • try setting frame to your placeholders inside HStack. Commented Sep 29, 2020 at 13:03

1 Answer 1

1

ScrollView does not know height of content, you have to specify it explicitly. By your code it looks like it should be

ScrollView(.horizontal, showsIndicators: false) {
    HStack {
        URLImage(URL(string: userData.profileURL)!, placeholder: Image(systemName: "circle"),
         content:  {
            $0.image
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: (UIScreen.main.bounds.width - 33), height: 500)
            }
        )

      // .. other content here

    }
    .frame(height: 500)     // << here !!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.