Pascal
Pascal

Reputation: 275

uiscrollview change image in imageview

i have a scroll view with 10 pages and un the last 6 I have an ImageView.

When I Tap on a Button my screen jumps to the right ImageView. But how can I change the Image on this ImageView on the Button click event?

Any Ideas?

ImageView1.image = [UIImage imageNamed:@"mhb2-1.jgp" ];

doesn't do anything

I create the ImageView in the ViewController.h

and in the "view did load":

if (pageNumber == 6) {
        ImageView1 = [[UIImageView alloc] initWithFrame:CGRectMake( 10.0, 50.0, 300.0, 300.0)];
        [ImageView1 setImage :[UIImage imageNamed:@"2.jpg"]];
        [self.view addSubview:ImageView1];

}

Upvotes: 1

Views: 321

Answers (2)

BhushanVU
BhushanVU

Reputation: 3455

give tags to your buttons, int selectedButtonTag; when button gets tapped use selectedButtonTag=button.Tag;

if(selectedButtonTag==2){
        [ImageView1 setImage :[UIImage imageNamed:@"2.jpg"]];
}
if(selectedButtonTag==3){
        [ImageView1 setImage :[UIImage imageNamed:@"3.jpg"]];
}

Upvotes: 1

Shailesh
Shailesh

Reputation: 3118

Shouldn't you be doing : [scrollView addSubView:ImageView1]; ??

Upvotes: 0

Related Questions