Determines the graphical offset or offsets for a string index.
SDKs
- iOS 3.2+
- macOS 10.5+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Core Text
Declaration
func CTLineGetOffsetForStringIndex(_ line: CTLine, _ charIndex: CFIndex, _ secondaryOffset: Unsafe Mutable Pointer<CGFloat>?) -> CGFloat
Parameters
line
The line from which the offset is requested.
charIndex
The string index corresponding to the desired position.
secondaryOffset
On output, the secondary offset along the baseline for
char
. When a single caret is sufficient for a string index, this value will be the same as the primary offset, which is the return value of this function. May beIndex NULL
.
Return Value
The primary offset along the baseline for char
, or 0
if the line does not support string access.
Discussion
This function returns the graphical offset or offsets corresponding to a string index, suitable for movement between adjacent lines or for drawing a custom caret. For moving between adjacent lines, the primary offset can be adjusted for any relative indentation of the two lines; a CGPoint
constructed with the adjusted offset for its x
value and 0
for its y
value is suitable for passing to CTLine
. For drawing a custom caret, the returned primary offset corresponds to the portion of the caret that represents the visual insertion location for a character whose direction matches the line's writing direction.