从uiimageview获取图像名称
问题描述:
我想通过触摸该图像内部来获取特定的图像名称。任何人都可以给我样本代码吗?
I want to get the particular image name by touching inside of that image. Can any one give me the sample code for that?
答
Nick Weaver是对的。不过还有一种方法可以做到。
Nick Weaver is correct. There is still a way to do it, though.
创建一个包含图像名称的数组。设置每个 UIImageView
的tag属性,使其对应于数组中的名称。然后,通过tag属性访问数组。
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];
另一种方法是创建 UIImageView
子类。