Instance Method

characterIndex(for:in:fractionOfDistanceBetweenInsertionPoints:)

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

Declaration

iOS, UIKit for Mac, tvOS
func characterIndex(for point: CGPoint, in container: NSTextContainer, fractionOfDistanceBetweenInsertionPoints partialFraction: UnsafeMutablePointer<CGFloat>?) -> Int
macOS
func characterIndex(for point: NSPoint, in container: NSTextContainer, fractionOfDistanceBetweenInsertionPoints partialFraction: UnsafeMutablePointer<CGFloat>?) -> Int

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 glyphIndex(for:in: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

func boundingRect(forGlyphRange: NSRange, in: NSTextContainer) -> CGRect

Returns a single bounding rectangle (in container coordinates) enclosing all glyphs and other marks drawn in the given text container for the given glyph range, including glyphs that draw outside their line fragment rectangles and text attributes such as underlining.

func characterRange(forGlyphRange: NSRange, actualGlyphRange: NSRangePointer?) -> NSRange

Returns the range of characters that generated the glyphs in the given glyph range.

func fractionOfDistanceThroughGlyph(for: CGPoint, in: NSTextContainer) -> CGFloat

This method is a primitive for glyphIndex(for:in:fractionOfDistanceThroughGlyph:). You should always call the main method, not the primitives.

func glyphIndex(for: CGPoint, in: NSTextContainer) -> Int

This method is a primitive for glyphIndex(for:in:fractionOfDistanceThroughGlyph:). You should always call the main method, not the primitives.

func glyphIndex(for: CGPoint, in: NSTextContainer, fractionOfDistanceThroughGlyph: UnsafeMutablePointer<CGFloat>?) -> Int

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

func glyphRange(forBoundingRect: CGRect, in: NSTextContainer) -> NSRange

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

func glyphRange(forBoundingRectWithoutAdditionalLayout: CGRect, in: NSTextContainer) -> NSRange

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

func glyphRange(for: NSTextContainer) -> NSRange

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

func glyphRange(forCharacterRange: NSRange, actualCharacterRange: NSRangePointer?) -> NSRange

Returns the range of glyphs that are generated from the characters in the given character range.

func range(ofNominallySpacedGlyphsContaining: Int) -> NSRange

Returns the range for the glyphs around the given glyph that can be displayed using only their advancements from the font, without pairwise kerning or other adjustments to spacing.