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

发布于 2024-12-27 03:09:51 字数 354 浏览 3 评论 0原文

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巡山小妖精 2025-01-03 03:09:51

也许您可以使用“

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

现在新位置”

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

进行计算,对于 y 类似,您需要考虑 x 的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文