3

I have a string coming from server which I am displaying on UILabel. It is within that string, I am identifying some particular substring. I want to place a button on that substring(button will be a subview of UILabel). For this I require substring coordinates. I went through this Gist but I am not able to understand it.

Suppose my complete string is abc, 567-324-6554, New York. I want 567-324-6554 to be displayed on button, for which I need its coordinates. How can I use above link to find coordinates of substring?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263

1 Answers1

5

Might be you can calculate using-

CGSize stringSize = [string sizeWithFont:myFont 
                       constrainedToSize:maximumSize 
                           lineBreakMode:self.myLabel.lineBreakMode];

Now New position-

x = self.myLabel.frame.origin.x + stringSize.width

and for y similarly you need to have code with consideration of x.

rishi
  • 11,779
  • 4
  • 40
  • 59
  • 1
    This could be useful. But the text is sometimes coming in single line and sometimes in multiple lines. – Nitish Jan 14 '12 at 06:37
  • the text in your label after which you wish to have button is your string. And regarding your first question i already wrote that you need to consider for y more because of multiple line text. – rishi Jan 14 '12 at 06:41
  • And what will be maximumSize? – Nitish Jan 14 '12 at 06:48
  • size of total text inside that label(including button text as well.) – rishi Jan 14 '12 at 08:24