2011-07-26 4 views
0
  • 現在の文字のインデックスを指定すると、選択した文字がある行の数はどのように決定できますか?目的C - Coreテキスト、行内の文字数?

  • CTLineを指定すると、どのようにして文字数が決まりますか?最初のもののために

+0

私の答えはあなたの使用でしたか? – Joshua

答えて

1

int currentCharacterIndex = 12; // You define this. 
CFArrayRef lines = CTFrameGetLines(frame); 
int currentLine = 0; 
for (CTLineRef line in lines) { 
    currentLine++; 
    CFRange range = CTLineGetStringRange(line); 
    if (currentCharacterIndex > range.location) 
     break; 
} 
// Current line is now the line that the currentCharacterIndex resides at 

秒1の場合:

CFRange range = CTLineGetStringRange(line); 
CFIndex length = range.length; // Number of characters 

確認することはできませんこれらの作業私はそれらをテストしていませんが、それは行く価値があるとして、 。

関連する問題