在UITextView中查找指定单词的(x,y)坐标 [英] Finding (x,y) coordinate of specified word in UITextView

查看:113
本文介绍了在UITextView中查找指定单词的(x,y)坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在UITextView中的内容......

Here is my contents in UITextView...

==>A'Metropolitan'用餐体验提供精致的食物,注重视觉细节和味道。

==>"A ‘Metropolitan’ dining experience offering exquisite food prepared with attention to visual detail & taste."

现在我的问题很简单,如何在textview中找到体验一词的位置(x,y)。

Now my question is simple and short,how to find the location(x,y) of a word "experience" within the textview.

任何解决方案都将不胜感激。

Any solution will be greatly appreciated.

推荐答案

使用sizeWithFont,它假设是类似的这个:

use sizeWithFont, it suppose to be something like this:

NSString *text = textView.text;
NSString *substring = [text substringToIndex:[text rangeOfString:@"experience"].location];
CGSize size = [substring sizeWithFont:textView.font];
CGPoint p = CGPointMake((int)size.width % (int)textView.frame.size.width, ((int)size.width / (int)textView.frame.size.width) * size.height);

这篇关于在UITextView中查找指定单词的(x,y)坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆