CrazySoftware
CrazySoftware

Reputation: 133

Images with URL link

I'll try to explain my doubt, but please consider that I'm new to Xcode and I have a lot of things to learn. In my iPhone App I'd like that when I touch an image, the app redirects to an external web URL. Is it possible to do it directly from the Storyboard? I didn't used a ViewController, so I can't call the function.

Thank you in advance.

Upvotes: 2

Views: 3016

Answers (3)

Mrunal
Mrunal

Reputation: 14118

Easier option is, that I would suggest is use a UIButton with required image, and provide button action method which opens your web URL.

If you want to go with UIImageView only, then add tap gesture recognizer over that, which gives you tap event. Over that event method, you can call your web URL.

Here is a link which provide detail explanation about gesture recognizer.

Hope this will help you.

Upvotes: 1

Thanakron Tandavas
Thanakron Tandavas

Reputation: 5683

  1. Add a button to your Storyboard.
  2. Set the button as custom and assign the image as the background of the button.
  3. Launch the Safari browser with your URL from the IBAction of your button.

Here is how to launch the Safari browser with your URL (got this code from here) :

NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url])

Upvotes: 2

Maverick1st
Maverick1st

Reputation: 3770

You can use a UIButton instead of a UIImage and assign the image to the Button in your InterfaceBuilder.

In the IBAction Outlet which must be connected to your UIButton you must then write the following Code:

NSURL *url = [ [ NSURL alloc ] initWithString: @"http://www.cnn.com" ];
[[UIApplication sharedApplication] openURL:url]; 

Since you have to link your storyboard Outlets to a Viewcontroller to handle the UIButton taps, you must use a ViewController.

I also strongly recommend to read about the basics of the MVC Pattern Apple uses in his Apps. I've never seen someone to write an app without using Viewcontrollers. They usually contain all your App Logic.

Upvotes: 0

Related Questions