我正在尝试编写可以更改UIImageView中的图像列表的UIButton。下面列出了代码。但是,在更改了所有图像并到达最后一个图像后,需要单击该按钮两次才能返回到第一个图像。我可以知道如何修改它吗?
全部谢谢。
-(IBAction)changeimage:(id)sender{
if (currentimage ==0) {
NSString *strTemp = [[NSString alloc]initWithString:@"stamp.png"];
currentimage =1;
aImage.image=[UIImage imageNamed:strTemp];
}
else if (currentimage ==1) {
NSString *strTemp = [[NSString alloc]initWithString:@"yoda.jpg"];
currentimage =2;
aImage.image=[UIImage imageNamed:strTemp];
}
else if (currentimage ==2) {
NSString *strTemp = [[NSString alloc]initWithString:@"44cents.jpg"];
currentimage =3;
aImage.image=[UIImage imageNamed:strTemp];
}
else (currentstamp =0);
}
答案 0 :(得分:1)
非常简单
-(IBAction)changeimage:(id)sender{
if(currentimage == 3){
currentimage = 0;
}
if (currentimage ==0) {
NSString *strTemp = [[NSString alloc]initWithString:@"stamp.png"];
currentimage =1;
aImage.image=[UIImage imageNamed:strTemp];
}
else if (currentimage ==1) {
NSString *strTemp = [[NSString alloc]initWithString:@"yoda.jpg"];
currentimage =2;
aImage.image=[UIImage imageNamed:strTemp];
}
else if (currentimage ==2) {
NSString *strTemp = [[NSString alloc]initWithString:@"44cents.jpg"];
currentimage =3;
aImage.image=[UIImage imageNamed:strTemp];
}