PDA

View Full Version : Linking a button or image to a url...




furycd001
May 8, 2013, 11:49 AM
HI everyone

How would I go about linking a button or an image to a url in xcode / interface builder :?

Basically what I would like to do is have a button or image within an app on my mac desktop, that whenever clicked it will take me to a specified hardcoded url. All the tutorials I have found online refer to creating IOS based apps. Any help would be appreciated & sorry is this is a dead silly question...



larswik
May 11, 2013, 02:31 AM
What have you tried so far that didn't work?

furycd001
May 11, 2013, 10:29 AM
What have you tried so far that didn't work?

I haven't really tried anything because I am unsure of what to connect the button to. I have though tried following some tutorials though they were iphone based, so I new they wouldn't work.

Someone on a programming irc channel told me to try the following...
Try creating an action handler in the script object, then connecting the button to the newly created handler. The code in the handler will check to see what button was pressed, then it will take the appropriate action.
If this would work how would I go about creating an action handler ??

Sorry but I am relatively new to programming & still learning. Your help will be much appreciated.

ArtOfWarfare
May 11, 2013, 06:51 PM
iOS and OS X are pretty darn similar... I would suspect that you can follow an iOS tutorial for this task to the t for an OS X app and end up with the same app (but for OS X, of course.)

Edit: Well, the code for opening the URL might change... Try just hooking up a button to an IBAction that NSLogs the URL first. Then you can look into opening a URL on OS X.

xStep
May 12, 2013, 01:30 AM
Basically what I would like to do is have a button or image within an app on my mac desktop, that whenever clicked it will take me to a specified hardcoded url.

I'm confused. Which is it? You want an icon on your desktop that you can double click to go to a specific URL, or you want a button within an app that takes you to a URL? Those are two different things.

If the first, simply drag the URL from Safari to the desktop. Automator maybe another simple option for this tactic.

If the second, look at using the openURL: method of the NSWorkspace.

NSURL * mtDotCom = [NSURL URLWithString: @"http://www.morphedthoughts.com"];
[[NSWorkspace sharedWorkspace] openURL: mtDotCom];

furycd001
May 12, 2013, 03:51 AM
Thanks for the replies everyone.

No I don't want an icon on my desktop, I was just either going to use a button or an image for the link in my app (i've decided on button). Thank you for the snippet of code, I will give that a whirl & see what happens. I will also try IBAction too...

xStep
May 12, 2013, 12:01 PM
That snipet of code will work well within an action method. That is how I tested it. :)

furycd001
May 17, 2013, 05:52 PM
Thank you for your help, I got everything working :-)