How to get Image Name used in an UIImage?
34,383
Solution 1
That functionality is not built-in to UIImage
because images are not always loaded from files. However, you could create a custom UIImageView
subclass to fit your needs.
Solution 2
It is not possible. UIImage instance contains the actual image data without any reference to the filename.
Solution 3
this code will help you out
NSString *imgName = [self.imgView1st image].accessibilityIdentifier;
NSLog(@"%@",imgName);
[self.imgView2nd setImage:[UIImage imageNamed:imgName]];
Solution 4
Images do not necessarily come from files or other named sources, so not all images even have a name. When you create an image from a file, you could store the name in a separate NSString*
, and then refer to that stored name when necessary.
Related videos on Youtube
Author by
Eager Beaver
Updated on July 09, 2022Comments
-
Eager Beaver almost 2 years
I am using an UIImage, in which I have an Image, and I want to know the name of image.
-
The iOSDev about 12 yearsi dont think it is possible to get the name of image
-
Hasan Sawaed almost 11 yearsAnswer: UIImageView - How to get the file name of the image assigned? stackoverflow.com/a/16885708/2316831?stw=2
-
-
Evan Mulawski almost 11 years@JayD: Not directly from an instance of
UIImage
. -
Silviu St almost 10 yearsthis doesn't work because you have to set the accesibiliyIdentifier when assining image
-
user464230 about 2 yearsThis is definitely the right answer! People should upvote it. When loading images via local bundle, using XCAssets, the runtime itself will automatically assign the
accessibilityIdentifier
to be the same as the asset name. When loading images dynamically or creating it dynamically, of course there is no built-in solution -
user464230 about 2 yearsWrong, @junaidsidhu has nailed it corretly
-
amadour almost 2 yearsThe
accessibilityIdentifier
is exposed only when accessibility is enabled on the device. This might be the case that it works for you in development on the simulator, but won't work on actual user's device.