UILabel 内的 iPhone 应用程序自定义图像
我有一个场景,我想找到 UILabel 中文本的结尾位置并获取其 x 和 y 坐标。然后我需要在 UILabel 文本的最后一个单词之后插入图像。当我单击应用程序中的特定图像时,将触发此事件。如何找到 UILabel 文本的结束字符的 x 和 y 是什么?
问候 阿亚兹阿拉维
I have got scenario where i would like to find where text in UILabel is ending and get its coordinates in terms of x and y. Then I need to insert image right after last word of UILabel text. This event will be fired when I click on particular image in app. How can I find what are the x and y of ending character of UILabel text?
Regards
ayaz alavi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Yang 的方法看起来不错,但是如果您出于某种原因不想调整标签大小(文本居中、文本会更改等),您可以在 NSString 中使用 UIKit 添加。当然,这仅适用于单行标签。
Yang's approach seems fine, but if you don't want to resize the label for some reason (text is centered, text will change, etc.), you might use the UIKit additions in NSString. Of course, this will only work properly for one-line labels.
您可以调整标签大小,然后获取坐标并将其用于图像视图:(
请注意,使用这种方法,您会遇到多行标签的问题,其中最后一行不是最长的。)
You could resize the label, then get the coordinates and use them for your image view:
(Note that with this approach you'll run into problems with multi-line labels where the last line is not the longest.)
我通过使用 iphone 和 UI textarea 支持的 unicode smileys 解决了这个问题。所以我只是继续将 unicode 字符附加到字段中的文本中,并且它继续向我显示图像。
I solved this issue by using unicode smileys which are supported by iphone and UI textarea. so i just keep on appending unicode characters to the text in the field and it keeps on showing me images.