Hello we have been working with an array to get a random image to display on the screen when a button is pressed.
This works, and everytime the button is pressed, a random image from our set is displayed.
However, the image always seems to display in the top left corner of the view, where we are trying to get it in the center of the screen.
We are trying to connect it up with a UIImage view, which is connected along with the view itself to a second view controller- whether that is what we are supposed to do or not, we dont know haha.
So if there is a bit of code to center the displayed image or place it IN a UIImage view, we would appreciate help.
Here is our code when the button is clicked:
Quote:
(IBAction)startClick id)sender
{
[start removeFromSuperview];
myArray = [[NSMutableArray alloc] init];
[myArray addObject:[UIImage imageNamed:@"1.png"]];
[myArray addObject:[UIImage imageNamed:@"2.png"]];
[myArray addObject:[UIImage imageNamed:@"0.png"]];
start = [[UIImageView alloc] initWithImage:[myArray objectAtIndex arc4random() % [myArray count])]];
[self.view addSubview:start];
[start release];
}
|
also, as a bonus, would anyone be able to tell us how to make it so the randomized images are not displayed twice.
(so it would show 1,3,4,2 or somthing like that as opposed to 1,1,1,2,2,4,3,2, etc.)