是否有其他方法可以获取当前设置为UIImageView的图像名称? [英] Any alternative to get Image name that is currently set to UIImageView?

查看:35
本文介绍了是否有其他方法可以获取当前设置为UIImageView的图像名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIImageView和大约5张图像,这些图像在计时器的帮助下不时更改.我们可以在UIImage中获得当前设置的图像名称吗?我的代码如下:-

I am using a UIImageView and about 5 images that is changing time to time with the help of timer. Can we get currently set image name in UIImage.I google it and found a that by inserting image names to array and by setting tag to imageView we can get image name by its tag but in my case there is only one imageView and images are 5.My code is given below:--

[_imgView setImage:[UIImage imageNamed:@"tops.png"]];
imgArray=[[NSArray alloc] initWithObjects:@"tops.png",@"position_conv.png",@"stocks.png",@"home.png",@"report.png",nil];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(change) userInfo:nil repeats:YES];

-(void)change
{
    int randNum = rand() % (4 - 0) + 0; 
    [_imgView setImage:[UIImage imageNamed:[imgArray objectAtIndex:randNum]]];
}

谢谢!

推荐答案

您可以使用UIImageView图像的可访问性标识符属性.在您的方法中设置图像可访问性标识符并获得所需的任何位置.

you can use Accessibility identifier property of UIImageView's image.Set image accessibility identifier in your method and get anywhere you want.

-(void)change
{
    int randNum = rand() % (4 - 0) + 0;
    [_imgView setImage:[UIImage imageNamed:[imgArray objectAtIndex:randNum]]];
    [_imgView.image setAccessibilityIdentifier:[imgArray objectAtIndex:randNum]];
}


- (IBAction)currentImgName:(id)sender {
    NSLog(@"image name is %@", [_imgView.image accessibilityIdentifier]);
}

这篇关于是否有其他方法可以获取当前设置为UIImageView的图像名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆