views:

79

answers:

2

Hello

I have looked around and found some code which so called chooses an image from an array of image objects, but cant find an explanation.

I would like to make my app have a background image and the user can select next and previous buttons to scroll through some full screen images, setting them as the background image as they scroll.

I know how to do this in java, but cant seem to do it for this app.

How or what code is linked to a next button to grab the next image in the array and reverse for the back button?

Then that needs to be displayed obviously.

I have used a layered architecture with a MVC style approach but cant seem to put it together with Objective-C.

Would the buttons call the appropriate methods of the so called delegates, which the delegates handle fetching and returning the Images?

Would the buttons use the returned images and actually handle the redrawing?

I would really appreciate the help.

Regards

Jarryd

+1  A: 

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pic.png"]];

syoleen
Thanks, but that needs to be hard coded for each image. I would like to grab images from an array. Keeping a value reference to the index for which image is loaded.appreciate the help.Regards
alJaree
+2  A: 

Extend the answer by syoleen.

NSArray * names = [NSArray arrayWithObjects:@"file1.png" @"file2.png",@"file3.png",nil];
int r=rand()%([NSArray count]);
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[names objectAtIndex:r]]];

(this is from memory so might have few typos)

John Smith
thanks a lot for this. So I could just put the following code in the next and previous buttons.r++; or r--; respectively.self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:[names objectAtIndex:r]]];Obviously need to make the r available to all(statically in java, but static is only available to the same class) Would this r value need to be memory managed?Regards.
alJaree