スクロールビューの下にimageViewがあります。スクロールビューから特定の画像を選択すると、画面の中央に表示されます。別の画像を選択すると、前の画像が消えます。画面に複数の画像を表示できません。
コード:
- (void)viewDidAppear:(BOOL)animated {
myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 10, 200, 200)];
[self.view addSubview:myImageView];
}
- (void)loadNextPage:(int)index {
int countFlag = 0;
for(int i=index*4;i<(index+1)*4;i++)
{
UIButton *imageView=[[UIButton alloc]initWithFrame:CGRectMake((320*index)+countFlag*80+ 2, 5, 75, 75)];
imageView.tag=i+1;
[imageView addTarget:self action:@selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
//[imageView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
// [imageView.layer setBorderWidth:1.0f];
switch ((i+1)%15) {
case 0:
[imageView setImage:[UIImage imageNamed:@"img.png"] forState:UIControlStateNormal];
break;
case 1:
[imageView setImage:[UIImage imageNamed:@"img1.png"] forState:UIControlStateNormal];
break;
case 2:
[imageView setImage:[UIImage imageNamed:@"img2.png"] forState:UIControlStateNormal];
break;
case 3:
[imageView setImage:[UIImage imageNamed:@"img3.png"] forState:UIControlStateNormal];
break;
case 4:
[imageView setImage:[UIImage imageNamed:@"img4.png"] forState:UIControlStateNormal];
break;
case 5:
[imageView setImage:[UIImage imageNamed:@"img5.png"] forState:UIControlStateNormal];
break;
break;
}
[myScrollView addSubview:imageView];
countFlag++;
}
}
- (void)imageViewClicked:(id)sender{
switch ([sender tag]%15) {
case 0:
[myImageView setImage:[UIImage imageNamed:@"img.png"]];
// myImageView.tag=1;
[myImageView setTag:0];
break;
case 1:
[myImageView setImage:[UIImage imageNamed:@"img1.png"]];
// myImageView.tag=2;
[myImageView setTag:1];
break;
case 2:
[myImageView setImage:[UIImage imageNamed:@"img2.png"]];
[myImageView setTag:2];
break;
case 3:
[myImageView setImage:[UIImage imageNamed:@"img3.png"]];
[myImageView setTag:3];
break;
case 4:
[myImageView setImage:[UIImage imageNamed:@"img4.png"]];
[myImageView setTag:4];
break;
case 5:
[myImageView setImage:[UIImage imageNamed:@"img5.png"]];
[myImageView setTag:5];
break;
}
[self.view addSubview:myImageView];
}