I have 5 images I would like to display on the view randomly. My image names are as follows: image-0, image-1, image-2, image-3, image-4.
What I need is I want to display each image, but the problem is when I write the code to display a second, it stacks on top of the first image. Here is my code to display one of my images:
- (void)viewDidLoad
{
int xValue = arc4random() % 320;
int yValue = arc4random() % 480;
image.center = CGPointMake(xValue, yValue);
{UIImageView *imgFive = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image-5.png"]];
[self.view addSubview:imgFive];
imgFive.center = CGPointMake(xValue, yValue);}
But if I add the same code but instead of "image-5.png" I use the other file names to try and display them, they stack on top of eachother. My images are circles, each varying size. So when I try and display all 5 I can see my circles have stacked on top of eachother from smallest to largest.
What do I need to do to separate these images from eachother? Do I need to put these images in an array and then loop through the array to display them how I would like?
Any help is appreciated, I am very new to coding so a simple explanation would be helpful in explaining why your code works.
Thanks again!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…