Knodel
Knodel

Reputation: 4389

UIImageView as a link to a URL

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

Upvotes: 2

Views: 2961

Answers (1)

glorifiedHacker
glorifiedHacker

Reputation: 6420

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.

Upvotes: 7

Related Questions