UIImageView - 如何获取分配的图像的文件名? [英] UIImageView - How to get the file name of the image assigned?
问题描述
是否可以读取当前存储在中的 UIImageView的
UIImage
的名称。 code> UIImageView ?
我希望你能做一些这样的事情,但没有想出来。 / p>
NSString * currentImageName = [MyIImageView getFileName];
原因是 UIImageView
实例不存储图像文件。它存储一个显示 UIImage
实例。当您从文件中创建图像时,您可以这样做:
UIImage * picture = [UIImage imageNamed:@myFile .png];
一旦这样做,就不再有任何对文件名的引用。 UIImage
实例包含数据,无论它在哪里。因此, UIImageView
无法知道文件名。
此外,即使你可以,从视图获取文件名信息。这会打破MVC。
Is it possible to read the name of an UIImageView's
UIImage
that's presently stored in the UIImageView
?
I was hoping you could do something kind of like this, but haven't figured it out.
NSString *currentImageName = [MyIImageView getFileName];
Nope. You can't do that.
The reason is that a UIImageView
instance does not store an image file. It stores a displays a UIImage
instance. When you make an image from a file, you do something like this:
UIImage *picture = [UIImage imageNamed:@"myFile.png"];
Once this is done, there is no longer any reference to the filename. The UIImage
instance contains the data, regardless of where it got it. Thus, the UIImageView
couldn't possibly know the filename.
Also, even if you could, you would never get filename info from a view. That breaks MVC.
这篇关于UIImageView - 如何获取分配的图像的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!