在UILabel中查找子字符串的坐标

问题描述:

我有一个来自服务器的字符串,我在UILabel上显示。它在该字符串中,我正在识别一些特定的子字符串。我想在子字符串上放置一个按钮(按钮将是UILabel的子视图)。为此,我需要子串坐标。我浏览了这个要点,但我无法理解。

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.

假设我的完整字符串是 abc,567-324-6554,纽约。我希望 567-324-6554 显示在按钮上,我需要它的坐标。如何使用上面的链接查找子串的坐标?

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?

您可以使用计算 -

Might be you can calculate using-

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

现在新头寸 -

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

对于y,同样你需要考虑x的代码。

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