Reputation:
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]]];
}
Thanks!
Upvotes: 1
Views: 2476
Reputation: 20021
You can use setAccessibilityIdentifier method for any subclass of UIView
UIImageView *image ;
[image setAccessibilityIdentifier:@"file name"] ;
NSString *file_name = [image accessibilityIdentifier] ;
Upvotes: 0
Reputation: 12641
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]);
}
Upvotes: 2