Convert a string to http link

Discussion in 'iOS Programming' started by ilx.mac, Jun 4, 2009.

  1. ilx.mac macrumors member

    Joined:
    Mar 10, 2009
    #1
    Hi there,

    I have a string like: @"www.macrumors.com". And I am placing it in a UILabel. All i want to do is to set a hyperlink for that value in UILable. I am new to this. can some one help me please?

    Thanks in advance!:D
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    A UILabel is not an HTML-aware object. I think you will either need to code a response to the touching of the label that performs a URL navigation or you will need to use a UIWebView which is HTML-aware.
     
  3. ilx.mac thread starter macrumors member

    Joined:
    Mar 10, 2009
    #3
    Thanks for your reply dejo. But, I think I have not explained my problem in brief.

    #1. I am displaying a string "www.macrumors.com" in the label.
    #2. I have to set a hyperlink to "www.macrumors.com". (this is what i am not aware of)
    #3. How can I set the hyperlink to a string which is displayed in a UILabel?


    I hope this explains my problem in brief.

    Thanks in advance!:):)
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    What does 'set a hyperlink' mean?

    UILabels just display text. They have no other interactivity. The also don't display underlines so they don't have a built in way to display text that looks like a hyperlink (at least an underlined one).

    A UIButton can be used to display text and to perform an action when the user taps it.
     
  5. detz macrumors 65816

    Joined:
    Jun 29, 2007
    #5
    Yeah, hyperlinks are for web urls on webpages...nothing to do with a label. What is it you want, do you want a webpage to open when the label is clicked? Where/why is there a we address in the label?
     
  6. ilx.mac thread starter macrumors member

    Joined:
    Mar 10, 2009
    #6
    Sorry for the confusion caused. I want to have a hyperlink for a string.

    In HTML we would do it with a <a> </a> tag.
    Here I have a string which has value - www.macrumors.com. All I want to set a hyperlink to that after displaying it in a button/lable/textfield/textview.

    i am not aware of how to set the hyperlink. can you guys help me out? Please

    Thanks in advance!
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    And then what? You still haven't defined what 'set a hyperlink' means.

    We all know what a hyperlink is in html. It displays text in a distinctive way. When the link is clicked in a web browser the web browser does something, usually it opens a new page in the same web browser window.

    What does that have to do with button/lable/textfield/textview?

    What is it that you want to appear in the interface? What is it that you want to happen?

    What will you say if we say 'it's impossible?'
     
  8. hussulinux macrumors newbie

    Joined:
    Jul 5, 2009
    #8
    What he means is say you have a label and you have some text in it which contains a URL, so he wants that when someone clicks on the URL , the next page should load up a uiwebview with that link.
     
  9. boyplunder macrumors regular

    boyplunder

    Joined:
    Sep 8, 2008
    Location:
    UK
    #9
    I was asked on Friday if I could add a web address to the about view, or a toolbar button, that opened a URL in Safari. It might be neater, I thought, to add a webview to the app, but this is another conversation.

    Anyway, I realised I didn't know how, so I too am asking what the method is here.

    I found this, uiwebview-tutorial which I am currently reviewing for myself.

    The Thread starter seems to want to do it directly off a text line [Even if the URL is within a paragraph, I think], and probably needs a button, even if you can't see the 'button'.

    What are the other possibilities for doing this?
     
  10. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #10
    Since 3.0 UITextView has the ability to display links and opens mobileSafari if the link is clicked. I haven't tried this but it's the only way, other than using a web view, that I know of to do anything like this.

    Understand that UIWebView isn't a web browser. It can display web pages but using it as a general web browser probably will run into various problems. It's not very configurable and has very few callbacks. I guess that its main purpose is to display styled text content in controlled html documents.
     

Share This Page