0

I have a JSON file that has image urls for the front and back of a character. The pictures download from JSON and show correctly in my image views. However, I am now wanting to put these images into a scroll view so that I can switch between the two pictures. I am using SDWebImage to convert the urls to images.

This is how the images are set for the image views. Front:

 figImage.sd_setImage(with: URL(string: (figure?.image)!))

Back:

 figBackImage.sd_setImage(with: URL(string: (figure?.backImage)!))

How can I get the pictures into the scroll view?

3
  • What is the exact UI? are you trying to add these images in a tableViewCell or something? Commented Apr 8, 2018 at 21:12
  • The images are on a detail view controller. Commented Apr 8, 2018 at 21:18
  • If you want the image views in a scroll view, put them in a scroll view. Your question and issue are unclear. Commented Apr 8, 2018 at 21:23

1 Answer 1

1

This will enable paging (swiping the images) and will set the content size that will be paged (or you can set that using constraints which is better)

   scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * 2,   
   scrollView.frame.size.height);
   scrollView.pagingEnabled=YES;

Then you add the two images next to each other but only make the width of the scrollView to show the first one, that will make what you asked for

Sign up to request clarification or add additional context in comments.

3 Comments

This worked, but it makes the image small. Is there a way to make the images page like in a photo gallery?
why is the image small, and what's the problem with that, you have control of scroller width and imageView size, i don't think you have a technical problem :) , if you found the answer helpful don't forget to make it an accepted one and vote it up ^_^
You are correct. All I was forgetting was to change the x position of the second image view! Thank you :)

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.