1

I need some help on a trivia app that I am currently building. My question is, on each trivia question I would like to have a different background image that corresponds to each trivia question.

I sort of know how to do it but I am still really confused, I only know how to make an image a permanent background and not how to have it change for each question.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
C.Elam
  • 91
  • 1
  • 9
  • 1
    just use uiimageview in your storyboard and set your image in it. using auto layout pin it from [left,right,top,bottom]. – Chandan Aug 12 '16 at 06:18

1 Answers1

0

You can attach images with your question if you want different and unique images for all questions.

But if you want to use random images and repetition is allowed than you can use array of images and randomly choose from the one.

Dhruv Khatri
  • 803
  • 6
  • 15
  • yes i would like a certain image for each question but how do i attach a certain image to each question. an example would be great!!! Thanks for all the help!!!! – C.Elam Aug 12 '16 at 22:00
  • From where you are taking the questions.?? – Dhruv Khatri Aug 13 '16 at 03:35
  • I am not sure what you mean by that ? I am making a trivia app so each trivia question will have a corresponding image background. That is what my question to everyone is. – C.Elam Aug 13 '16 at 08:24
  • Ya I understand your question. But i am asking that you are fetching question from server or stored them locally..?? If you stored it on server you can also store image with each question because you want different image for each question. And if you are stored question on local database you have to add images in your project and have to make array of images and load them as you load your question – Dhruv Khatri Aug 13 '16 at 13:30
  • Got it..?? Or not.?? – Dhruv Khatri Aug 13 '16 at 13:31
  • I am storing the questions locally and I would also store the images locally, unless there is an easier way? – C.Elam Aug 13 '16 at 19:25
  • And thank you so very much for helping me I REALLY appreciate it!!!!!!! – C.Elam Aug 13 '16 at 19:26
  • If you don't want to change question regularly it is good to store them locally. But if you want to change the questions means you want to give new questions every day to user the best way is store them on server like Firebase. – Dhruv Khatri Aug 14 '16 at 05:14
  • I am sorry i just started doing this and i have never heard of a Firebase but i will look into it. But my thing is is how do i assign a specific image to a specific question. – C.Elam Aug 14 '16 at 05:23
  • there will be around 300-500 questions which means 300- 500 images and i don't want to take up a ton of storage on a persons phone – C.Elam Aug 14 '16 at 05:24
  • So firebase is good option for you. Other option is use mysql as local database and store image as data so you can reduce the size of your app. – Dhruv Khatri Aug 14 '16 at 05:28
  • I know your question is how to use unique image with each question. So simple you store image with your question in any database and fetch it with question. – Dhruv Khatri Aug 14 '16 at 05:30
  • Which one do you think would be the easiest or best one for what i need to do? and then how do you assig – C.Elam Aug 14 '16 at 06:09
  • assign it to show up everytime that question is called? – C.Elam Aug 14 '16 at 06:10
  • If your app use firebase you have to require internet connection. Without internet connection you didn't get any question. While you use sqlite your app will work offline. – Dhruv Khatri Aug 14 '16 at 06:12
  • And to assign image you have to store it on your device to use it offline. – Dhruv Khatri Aug 14 '16 at 06:12
  • Yes I would like offline – C.Elam Aug 14 '16 at 06:19
  • I will look into the SQLite – C.Elam Aug 14 '16 at 06:19
  • 1. http://stackoverflow.com/questions/10894337/saving-and-retrieving-images-to-and-from-sqlite-in-ios. 2.http://www.theappguruz.com/blog/use-sqlite-database-swift. This may help you – Dhruv Khatri Aug 14 '16 at 06:23
  • Thank you so much for everything!!!!!!!!!! I will look into everything and see if I can figure it out and if I have a question I will come back here and ask but thanks for everything!!!!!!!! It's my first time on stack overflow and I am extremely impressed with everything !!!!!!!! – C.Elam Aug 14 '16 at 06:57