iphone - 每次点击不同的图像

标签 iphone ios uiimageview

<分区>

在我的应用程序中,我有 4 张图片。我想在每次点击时显示不同的图像。如何在每次点击时显示不同的图像?

这是我的单张图片代码:

-(void)removeImageView
{   
    rightongbanner.image=Nil;
}

-(void)alertshow
{
    rightongbanner.image=[UIImage  imageNamed:@"correct.png"];
    timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(removeImageView) userInfo:nil repeats:NO];
    [aplayer play];
}

rightongbanner.image 中,我想在第一次点击时显示 img1,在第二次点击时显示 img2。我该怎么做?

最佳答案

这样试试,

.h

int a;

.m

-(void)loadView  {
    a=0;
}

-(void)alertshow
{
   if((a%4)==0)
       rightongbanner.image=[UIImage  imageNamed:@"correct1.png"];
   if((a%4)==1)
       rightongbanner.image=[UIImage  imageNamed:@"correct2.png"];
   if((a%4)==2)
       rightongbanner.image=[UIImage  imageNamed:@"correct3.png"];
   if((a%4)==3)
       rightongbanner.image=[UIImage  imageNamed:@"correct4.png"];

  timer = [NSTimer scheduledTimerWithTimeInterval:2.5 target:self selector:@selector(removeImageView) userInfo:nil repeats:NO];
     [aplayer play];
  a++;
}

关于iphone - 每次点击不同的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14053111/

相关文章:

iphone - UISegmentedControl 没有圆角?

ios - 未找到 Firebase 对象

c# - 我在说 "Assertion failed"之前从未见过的奇怪的 xCode 链接器错误

iphone - 当我使用导航 Controller 时 View 消失时出现黑条

iphone - 指定单元格 imageView 的宽度

iphone - iOS AWS SDK 和 CloudFront - 访问图像

iphone - 如何在 iphone 中列出我的 wifi 范围内的所有设备

ios - 在 iPhone 的导航栏中显示来自栏按钮的弹出窗口

iphone - 如何使用 UIImageView 调整图片大小以便放大和缩小?

ios - 如何在 UIStackView 中正确添加 UIImageView