查找子字符串的CGRect

时间:2014-09-01 17:02:50

标签: ios objective-c cocoa-touch nsstring

我想获取属性文本子字符串的坐标。这是前提的简化版本。

// Content
NSString *haystack = @"This is a paragraph of moderate length. I want to find a specific word within it. And then draw on top of that Word a rectangular shape.";
NSString *needle = @"word";

// Finding the needle
NSRange range = [haystack rangeOfString:needle];
range.location; // 66
range.length;   // 4

// Draw it
UILabel *label;
label.text = haystack;

该范围只能让我在大海捞针中找到针的特征位置。我需要针头的边界CGRect。这就是我想要实现的目标,UILabel

Before

上画一个圆角矩形。

After

0 个答案:

没有答案