Get url clickable in Lable string

Hi all,

How can we achieve this? I’ve a string with urls lets say “something http://www.google.com again http://www.amazon.com” or “http://www.google.com nexturl http://www.amazon.com”. Now what I want is, when I am showing this string (in a UILabel), I could make the link clickable, i.e., the link should act like a url, so that when I click it, it should open me the respective link.

Please provide me your suggestions on how to achieve this. Also I am using NGUI for showing labels.

Thanks in advance.

Anyone…? BUMP!!!

Seems like an easy solution would be to overlay a UIButton on the UILabel. You just need to compute the width of the text before the button and offset the button by this amount.

Better yet, you could pack them next to each other using anchors, so you have [UILabel][UIButton][UILabel] for “something http://www.google.com somethingelse”. Here’s the tutorial on NGUI 3’s new layout system: http://youtu.be/P8JTTE0JBXQ

And of course set your button style to match your label style, except maybe a different color to let the user know that it’s a link.

Okays …actually the first one is what I thought of at start…:slight_smile:
And I think, the second one could increase complexity if the string is bigger and contains many urls, there will be lot of elements then in the scene. Although I am not using the latest version of NGUI, I am using 2.6 and I cannot update it in the middle :frowning:

Anyway if I go with the first one, how could I get the bounds of a text inside of string, text.width does not work here…Also NGUIMath.CalculateAbsoluteWidgetBounds returns bound of the whole string/label not of the some text inside it…

Please explain this and thanks for the reply.

I’m not an expert with NGUI2. If you post the question on Tasharen’s forums, someone can probably help you.