If you have created all of these images and added them to the project, then you can just write a helper method to get yourself a random image. It might look like this:
- (UIImage*)getRandomColorImage
{
NSInteger kNumberOfColors = 5; // or however many color images you have
NSInteger randomNumber = arc4random() % kNumberOfColors;
if(randomNumber == 0)
{
return [UIImage imageNamed:@"red"];
}
else if (randomNumber == 1)
{
return [UIImage imageNamed:@"brown"];
}
else if (randomNumber == 2)
{
return [UIImage imageNamed:@"green"];
}
else if (randomNumber == 3)
{
return [UIImage imageNamed:@"gold"];
}
else
{
return [UIImage imageNamed:@"black"];
}
}
If you wanted to make things even more flexible, you could get rid of the images you added to the project and just create any colored image on the fly with the help of the Core Graphics library and this cool github repo: https://gist.github.com/kylefox/1689973 . The magic there is in these 4 lines (which generate a random color):
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];