Instance Method

characterIndexForPoint:inTextContainer:fractionOfDistanceBetweenInsertionPoints:

Returns the index of the character falling under the given point, expressed in the given container's coordinate system.

Declaration

iOS, Mac Catalyst, tvOS
- (NSUInteger)characterIndexForPoint:(CGPoint)point inTextContainer:(NSTextContainer *)container fractionOfDistanceBetweenInsertionPoints:(CGFloat *)partialFraction;
macOS
- (NSUInteger)characterIndexForPoint:(NSPoint)point inTextContainer:(NSTextContainer *)container fractionOfDistanceBetweenInsertionPoints:(CGFloat *)partialFraction;

Parameters

point

The point to test.

container

The text container within which the point is tested.

partialFraction

A fraction of the distance from the insertion point, logically before the given character to the next one.

Return Value

The index of the character falling under point.

Discussion

Analogous to glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:, but expressed in character index terms. The method returns the index of the character falling under point, expressed in coordinate system of container; if no character is under the point, the nearest character is returned, where nearest is defined according to the requirements of selection by mouse. However, this is not simply equivalent to taking the result of the corresponding glyph index method and converting it to a character index, because in some cases a single glyph represents more than one selectable character, for example an fi ligature glyph. In that case, there is an insertion point within the glyph, and this method returns one character or the other, depending on whether the specified point lies to the left or the right of that insertion point.

In general, this method returns only character indexes for which there is an insertion point. The partialFraction is a fraction of the distance from the insertion point, logically before the given character to the next one, which may be either to the right or to the left depending on directionality.

See Also

Performing Advanced Layout Queries

- boundingRectForGlyphRange:inTextContainer:

Returns the bounding rectangle for the specified glyphs in a container.

- characterRangeForGlyphRange:actualGlyphRange:

Returns the range of characters that correspond to the glyphs in the specified glyph range.

- enumerateEnclosingRectsForGlyphRange:withinSelectedGlyphRange:inTextContainer:usingBlock:

Enumerates enclosing rectangles for the specified glyph range in a text container.

- enumerateLineFragmentsForGlyphRange:usingBlock:

Enumerates line fragments intersecting with the specified glyph range.

- fractionOfDistanceThroughGlyphForPoint:inTextContainer:

Returns the fraction of the distance between the glyph at the specified point and the next glyph.

- glyphIndexForPoint:inTextContainer:

Returns the index of the glyph at the specified location in a text container.

- glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:

Returns the index of the glyph at the specified point, expressed in the container's coordinate system.

- glyphRangeForBoundingRect:inTextContainer:

Returns the smallest contiguous range for glyphs that are laid out wholly or partially within the specified rectangle of the text container.

- glyphRangeForBoundingRectWithoutAdditionalLayout:inTextContainer:

Returns the smallest contiguous range for glyphs that are laid out wholly or partially within the specified rectangle of the text container.

- glyphRangeForTextContainer:

Returns the range of glyphs laid out within the specified text container.

- glyphRangeForCharacterRange:actualCharacterRange:

Returns the range of glyphs that are generated from the specified range of characters.

- rangeOfNominallySpacedGlyphsContainingIndex:

Returns the range of displayable glyphs that surround the glyph at the specified index.