How to find a pixel-positon of a cursor in UITextView?

前端 未结 2 1731
小鲜肉
小鲜肉 2021-01-01 01:35

I\'m developing a simple writing app for iPad.

I\'m trying to compute the pixel-position of the cursor in UITextView. I spend a few weeks to design this

2条回答
  •  旧巷少年郎
    2021-01-01 02:06

    This is probably rather inefficient, but could you take the same basic principal of the code you have posted and take the line of text the cursor is on, and loop through each individual character and do [NSString sizeWithFont:forWidth:lineBreakMode:] to calculate each character's width, and you could add all those up for your x position? Just an idea, but may help fix the issue with word wrapping.

提交回复
热议问题