aryaxt
aryaxt

Reputation: 77646

Objective C - Core Text, number of characters in a line?

Upvotes: 0

Views: 530

Answers (1)

Joshua
Joshua

Reputation: 15520

For the first one:

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

For the second one:

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

Can't be sure these work as I haven't tested them but it's worth a go.

Upvotes: 1

Related Questions