ios 如何获取 UIImage 中使用的图像名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10279314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Image Name used in an UIImage?
提问by Eager Beaver
I am using an UIImage, in which I have an Image, and I want to know the name of image.
我正在使用 UIImage,其中有一个图像,我想知道图像的名称。
采纳答案by Evan Mulawski
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.
该功能不是内置的,UIImage
因为图像并不总是从文件加载。但是,您可以创建自定义UIImageView
子类以满足您的需要。
回答by Krishnabhadra
It is not possible. UIImage instance contains the actual image data without any reference to the filename.
这不可能。UIImage 实例包含实际的图像数据,没有对文件名的任何引用。
回答by dasblinkenlight
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.
图像不一定来自文件或其他命名来源,因此并非所有图像都有名称。当您从文件创建图像时,您可以将名称存储在单独的 中NSString*
,然后在必要时引用该存储的名称。
回答by junaidsidhu
this code will help you out
此代码将帮助您
NSString *imgName = [self.imgView1st image].accessibilityIdentifier;
NSLog(@"%@",imgName);
[self.imgView2nd setImage:[UIImage imageNamed:imgName]];