iPhone - Set UIImage position
image, iphone, objective-c, xcode
Solution
As the other two answers state, you can set the initial position of a UIImageView using a frame (or CGRect). Note that the parameters for the CGRectMake are; x position, y position, x dimension, y dimension.
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 100, 100)];
[imgView setImage:[UIImage imageNamed:"image.png"]];
To move the image each time you press a button, you'll need to update the frame each time the button is pressed. However, the x and y coordinates of a frame are read only, so you'll need to create a new frame like so:
CGRect oldFrame = imgView.frame;
CGRect newFrame = CGRectMake(oldFrame.origin.x + 10, oldFrame.origin.y, oldFrame.size.width, oldFrame.size.height);
imgView.frame = newFrame;
Note that this code moves the image 10 points to the right, (along the x axis).
Problem
I want to have an image that moves each time I hit a button. It should move a set value of pixels each time. I was hoping that image1 now would have a position property, but as far as I can see it doesnt't. ``` UIImageView *image1=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"indicator"]]; [self.view addSubview:image1]; ... ``` Thank you EDIT: `UIImageView *image1=[[UIImageView alloc]...`