Linking a button or image to a url...

Discussion in 'Mac Programming' started by furycd001, May 8, 2013.

  1. macrumors member

    furycd001

    Joined:
    Mar 9, 2011
    Location:
    Belfast
    #1
    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...
     
  2. macrumors 68000

    Joined:
    Sep 8, 2006
    #2
    What have you tried so far that didn't work?
     
  3. thread starter macrumors member

    furycd001

    Joined:
    Mar 9, 2011
    Location:
    Belfast
    #3
    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...
    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.
     
  4. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    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.
     
  5. macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #5
    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.
    Code:
       NSURL * mtDotCom = [NSURL URLWithString: @"http://www.morphedthoughts.com"];
       [[NSWorkspace sharedWorkspace] openURL: mtDotCom];
    
     
  6. thread starter macrumors member

    furycd001

    Joined:
    Mar 9, 2011
    Location:
    Belfast
    #6
    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...
     
  7. macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #7
    That snipet of code will work well within an action method. That is how I tested it. :)
     
  8. thread starter macrumors member

    furycd001

    Joined:
    Mar 9, 2011
    Location:
    Belfast
    #8
    Thank you for your help, I got everything working :)
     

Share This Page