I am trying to get the index of the closest character to a point.
The code below works perfectly fine as ling as my text alignment is set to left, as soon as I chage it to right or center it gives me the wrong index. What would be the solution to consider the text alignment while getting closest index to a point?
CTLineRef line = (CTLineRef)[lines objectAtIndex:i];
index = CTLineGetStringIndexForPosition(line, point);
EDIT:
My text alignment is done by adding a paragraph style that has it's textAlignment setting to kCTCenterTextAlignment
该点相对于线的原点(随着对齐而变化),因此您必须使用CTFrameGetLineOrigins
并将线的原点的x值添加到点的x值。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.