predict location of single-line text from a UITextView

Posted by William Jockusch on Stack Overflow See other posts from Stack Overflow or by William Jockusch
Published on 2011-01-05T22:04:55Z Indexed on 2011/01/06 14:53 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

Is this possible? Specifically, I have a UITextView, and the text is short enough that it will fit on a single line. I want to predict where it will appear, so that (for example) if I wanted to, I could set up a UILabel that rendered the text in exactly the same location.

Once I get that figured out, what I really want to do is pick contentInset and/or contentOffset so that the text of the UITextView and the left-justified UILabel will render in the same location. But I figure the above will let me do that.

EDIT: In response to a comment, the fundamental problem I am trying to get around is that UITextField does not let you set the location of the cursor. It appears a lot of people have tried to get around this without success. I need to be able to move the cursor -- inserting/deleting text there is not enough.

Control cursor position in UITextField

Insert string at cursor position of UITextField

Moving the cursor to the beginning of UITextField

iOS -- dealing with the inability to set the cursor position in a UITextField

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios