如何在点击它时从不同的图像视图中获取图像标签
我想使用 nos 中的图像视图。单击任何特定图像视图时,滚动视图中的图像视图数。
I want to used image view from nos. of image views in scroll view on single tapping any particular image view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您坚持使用图像而不是按钮,您可以使用手势识别器。创建一个 imageView 并启用其 userInteraction
现在分配一个手势识别器对象并将其添加到您的 imageView...
现在在选择器“singleTap”中您可以执行任何操作...
希望这有帮助...干杯...
If you are insistent on using images instead of buttons you can use Gesture Recognizer. Create an imageView and enable its userInteraction
Now allocate a gesture Recognizer object and add it to your imageView...
Now in the selector "singleTap" you can do whatever your action is..
Hope this help...cheers....
创建一个按钮并将图像设置为背景。在创建按钮时,您可以设置类似标签
并在您的类中实现此功能,
同时点击特定按钮此功能将被调用。
Create a button and set image as background.while creating button you can set tag like
and implement this function in your clss
while tapping the particular button this function will get called.
您可以使用以图像视图作为内容的 UIButton,而不是使用图像视图。
这样,当通过引用按钮点击给定图像时,您将收到回调。从那里你应该能够获得已被点击的标签!
Rather than use image views, you could use UIButtons with image views as their content.
That way, you'll get a callback when a given image is tapped with a reference to the button. From there you should be able to get the tag of that which has been tapped!
你可以按照尼克的建议去做。
或者,您可以创建 imageview 的子类。设置框架和标签。
在这个自定义类的touchesEnded方法中,你可以根据它的标签找到它是哪个imageview。
You can do according to what Nick has suggested.
Or else, you can create a subclass of the imageview. Set frame and tag to it.
In touchesEnded method of this custom class, you can find which imageview it is based on its tag.