- Home /
Set URL as 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.
EDIT : Found this on NGUI Forum, this is related to my ques but no help : [http://www.tasharen.com/forum/index.php?topic=7809.0][1] [1]: http://www.tasharen.com/forum/index.php?topic=7809.0 :(
Answer by GameVortex · Feb 04, 2014 at 01:02 PM
Detect button click normally like one always do in NGUI and then us **Application.OpenURL** to open the url:
private void OnClick()
{
Application.OpenURL(url);
}
Yes, this is correct, but actually my problem is : I am getting the above string as a response and I have to display this string as half text and half url (which can be clicked). So actually I wanted to achieve this first....then the clicking part could be done according to this!!!
You would have to separate out the url and display it on its own UILabel, or resize the collider for the UILabel yourself so it only covers the url.
Yes I found this the ONE way to display text and url as on their different UILabel's. But I am stuck in some situation...I mean what if the url string is bigger..and it then displayed/moved to the next line also..then how could I manage that Label's collider ..
Answer by EdwardLM · Feb 06, 2014 at 08:10 PM
I can think of two different approaches
· Limit the URL size, with the default options of "size" or just adjusting the .text variable of that UILabel to do whatever you want. For example: when the size of a URL exceeds 30 characters, replace the last characters for "(...)"
· Put only one UILabel, it will have the entire text + URL. Over it, there will be an invisible button the size of the URL. You will have to position this invisible button exactly on the top of URL. To me, this seems a bit more "dirty", but if this is only for an isolated case and not meant to be reused in the rest of the project, it may work for you.