UITextView と NSAttributedString を使用してそれを行う簡単な方法を次に示します。
- リンクの文字範囲を取得するには、正規表現を使用します。
- 一致した範囲にリンク スタイルを追加します。
- 実行するタップ アクションを参照するカスタム属性を範囲に追加します。
- タッチ時に、文字のインデックスが一致した範囲内にある場合は、リンクの書式を変更して強調表示し、関連するタップ アクションを実行します。
iOS7 で位置の文字のインデックスを取得する方法:
- (NSUInteger) getCharIndexAt: (CGPoint) location
{
NSLayoutManager *layoutManager = self.layoutManager;
NSUInteger characterIndex = NSNotFound;
characterIndex = [layoutManager characterIndexForPoint:location inTextContainer:self.textContainer fractionOfDistanceBetweenInsertionPoints:NULL];
return characterIndex;
}
WWDC 2013 intro to TextKit Demo もチェックしてください。
iOS7 テキスト ユーティリティ