Author Topic: About UILabel font  (Read 8346 times)

shokinhan

  • Guest
About UILabel font
« on: June 12, 2012, 01:27:02 AM »
I have used the uilabel , but i dont't know how to calculate the string's position at uilabel.

I want to do link about string, when i click the string can trige some event. so i add a button above on the special string ,but i don't know how to calculate the button's position.

eg: "hello world, i like ngui, 123456" . I want to know the position of  the string "i like ngui" at uilabel. If i know the position at label , so i can judge  the string has some other sprite, and add some sprite above on the special string!

thanks very much!

joreldraw

  • Guest
Re: About UILabel font
« Reply #1 on: June 12, 2012, 05:15:28 AM »
You need to add button ever in same character count position or you need to find a word?

shokinhan

  • Guest
Re: About UILabel font
« Reply #2 on: June 12, 2012, 08:41:14 AM »
yes, so I need know where the button above on.
Do you know how to do it ?

thanks very mush

PhilipC

  • Guest
Re: About UILabel font
« Reply #3 on: June 12, 2012, 09:08:08 AM »
This is going to seem like a long shot but i can think of 1 way you can do it a little hacky though.

In UIFont there is a method CalculatePrintedSize. As you know where the text you want is located in the UILabel.text (e.g. if you were looking for "1234" inside "Hello world, 1234" youd be looking at position 12). With this you could find the top left position (relative to the UILabel) by doing label.font.CalculatePrintedSize(label.text.substring(0, position), label.supportEncoding, lable.symbolStyle). You would then do the same for finding the bottom right corner. From there you could calculate you button size.

ryan

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 90
    • View Profile
Re: About UILabel font
« Reply #4 on: June 12, 2012, 12:02:52 PM »
I think that's not likely to work with line-wrapped text, but it might be good enough for his purposes.

PhilipC

  • Guest
Re: About UILabel font
« Reply #5 on: June 12, 2012, 12:27:33 PM »
You would be required to do a little more work for line wrapped text. i.e. you could have to calculate how many lines down the text is using UIFont.WrapText as well. This would give you the label.text with a '\n' at every new line which when counted will tell you how many lines down the text is.

shokinhan

  • Guest
Re: About UILabel font
« Reply #6 on: June 13, 2012, 09:24:02 AM »
Thanks all!

I will try..

If NGUI has support like html's href , it will be very perfect.


shokinhan

  • Guest
Re: About UILabel font
« Reply #7 on: June 13, 2012, 09:32:07 AM »
Dear PhilipC:
        Your's means is that I can add the UILabel.LocalPosition to uifont.CalculatePrintedSize , the sum is the text's localposition?


Thanks!!!




PhilipC

  • Guest
Re: About UILabel font
« Reply #8 on: June 13, 2012, 09:45:54 AM »
That is correct! (Have not tried to do this but that's how it should work in my head)