Key functions of CoreText
The CoreText class is really powerful.
1. This function is used to deal with the inconsistency of row width. Some rows cannot occupy the whole line due to some internal punctuation marks, resulting in uneven row width. This function is dedicated to this problem.
CTLineRef _ nullable CTLineCreateJustifiedLine (
CTLineRef line,
CGFloat justificationFactor,
Double justificationWidth) CT_AVAILABLE (10_5, 3_2 );
2. Obtain the x coordinates of characters at an index position in the middle of a row.
CGFloat CTLineGetOffsetForStringIndex (
CTLineRef line,
CFIndex charIndex,
CGFloat * _ nullable secondaryOffset) CT_AVAILABLE (10_5, 3_2 );
3. Obtain the index of the character position in the line based on the Coordinate Position of a point
CFIndex CTLineGetStringIndexForPosition (
CTLineRef line,
CGPoint position) CT_AVAILABLE (10_5, 3_2 );
4. obtain information about the row. The returned value is the overall width of the row, and the Row Height Is ascent + descent.
Double CTLineGetTypographicBounds (
CTLineRef line,
CGFloat * _ nullable ascent,
CGFloat * _ nullable descent,
CGFloat * _ nullable leading) CT_AVAILABLE (10_5, 3_2 );