Find substring coordinates in UILabel

I have a line coming from a server that I am showing on UILabel. It is within this line that I identify some specific substring. I want to put a button on this substring (the button will obey UILabel). For this I need subscript coordinates. I went through this Gist , but I can't figure it out.

Suppose my full line is abc, 567-324-6554, New York . I want 567-324-6554 to appear on the button for which I need its coordinates. How can I use the link above to find the substring coordinates?

+3
source share
1 answer

Perhaps you can calculate with -

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

Now a new position -

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

and for y, likewise you need to have code given x.

+5
source

All Articles