UIImageView作为URL的链接 [英] UIImageView as a link to a URL

查看:66
本文介绍了UIImageView作为URL的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使UIImageView在用户单击时在Safari中打开URL?

How to make a UIImageView open a URL in Safari when user clicks it?

推荐答案

我建议为此使用按钮.您可以使用所需的任何图像来创建自定义UIButton.这具有提供按钮的内置目标动作机制的优点,并且能够提供突出显示的图像以提供用户反馈.考虑使用类似这样的东西:

I would suggest using a button for this purpose instead. You can create a custom UIButton with whatever image you want. This gives the advantage of providing the built-in target-action mechanism of a button, as well as being able to provided a highlighted image to provide the user feedback. Consider using something like this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"regular_image.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"highlighted_image.png"] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(loadURL) forControlEvents:UIControlEventTouchUpInside];

请注意,对于用户而言,它仍然看起来像只是一幅图像".

Note that it will still look like "just an image" to the user.

这篇关于UIImageView作为URL的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆