How to move a UIButton and UImageView from one place to another automatically when i clicking a button. I’m also created a UIButton and UIImageView programmatically within scrollview. But i want when i clicking the button the another UIImage and also a button move to specified place.
Here is my code
if (i==0)
{
bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage.image = [UIImage imageNamed:@"iphone.png"];
[self.view addSubview:bgImage];
[scrollview addSubview:bgImage];
myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton setTitle:@"Delete" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
[scrollview addSubview:myButton];
x=x+100;
}
if (i==1)
{
bgImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(20,30+x,100,100)];
bgImage1.image = [UIImage imageNamed:@"iphone.png"];
[self.view addSubview:bgImage1];
[scrollview addSubview:bgImage1];
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton1.frame = CGRectMake(120, 65+x, 70, 30); // position in the parent view and set the size of the button
[myButton1 setTitle:@"Delete" forState:UIControlStateNormal];
[myButton1 addTarget:self action:@selector(buttonClicked1) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton1];
[scrollview addSubview:myButton1];
x=x+100;
}
- (void)buttonClicked1
{
[bgImage removeFromSuperview];
[bgImage release];
bgImage=nil;
myButton.enabled=NO;
myButton.hidden=YES;
}
When i clicking buttonclicked1 button the bgImage and myButton is removed its place and i want bgImage1 and myButton1 is moved to these place without any modification.
How to do this. Anybody give me the code pls. I cant move it. How to do this. Pls help me.
Thanks in advance.
Change the frame in the button click.Do this in – (void)buttonClicked1 method
or