What are all the ways to use 'caretRect' method of UITextField?

Hi

What are all the ways to use 'caretRect' method of UITextField?

Accepted Reply

No, don't need to subclass.


You can use directly on any instance.

Replies

You can get and set it.


What do you want to know in fact ? Have you something you would like to do ? Or just for the sake of understanding ?


You can find the caret rect for a selection:

See h ttps://stackoverflow.com/questions/43166781/cursor-position-in-relation-to-self-view


Or another use: when editing, keep caret at same vertical position on screen when you start a new line and scroll the existing text up:

h ttps://stackoverflow.com/questions/47625201/how-to-lock-caret-y-position-in-uitextview-to-create-typewriter-effect

Hi

for understanding purpose.

"func caretRect(for position: UITextPosition) -> CGRect { } " of UITextField , can be accessed only by subclassing UITextField or else any other way ?

No, don't need to subclass.


You can use directly on any instance.