Convert a string to http link

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

  1. ilx.mac macrumors member

    Mar 10, 2009
    Hi there,

    I have a string like: @"". 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


    Staff Member

    Sep 2, 2004
    The Centennial State
    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

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

    #1. I am displaying a string "" in the label.
    #2. I have to set a hyperlink to "". (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 68040


    Sep 2, 2008
    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

    Jun 29, 2007
    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

    Mar 10, 2009
    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 - 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 68040


    Sep 2, 2008
    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

    Jul 5, 2009
    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


    Sep 8, 2008
    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 68040


    Sep 2, 2008
    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