Getting image name from uiimageview

南楼画角 提交于 2019-12-11 06:54:23

问题


I want to get the particular image name by touching inside of that image. Can any one give me the sample code for that?


回答1:


Nick Weaver is correct. There is still a way to do it, though.

Create an array with the names of the images. Set the tag property of each UIImageView so it corresponds to the names in the array. Then, access the array via the tag property.

NSArray *nameArray = [NSArray arrayWithObjects:@"image1", @"image2", nil];

//touch happened

NSString *imageName = [nameArray objectAtIndex:imageView.tag];

Another method is creating a UIImageView subclass.




回答2:


UIImageView nor UIImage do store the name of the image you have used to create the image. You can subclass UIImageView and use your own initializer and an extra field to store the name.



来源:https://stackoverflow.com/questions/5676390/getting-image-name-from-uiimageview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!