Search code examples
iosobjective-cuitextinput

How to replace Text in UITextInput?


I use UITextInput in customView:

MyCode: https://github.com/lequysang/github_zip/blob/master/UITextInputDebug.zip

@property (strong,nonatomic) id<UITextInput> textInput;

After typing some chars, I want to go back 4 chars and replace text at this position (replace any to T).Current cursor at the end.

How to do that?

I try replaceRange with UITextRange but don't know how to get position and size with it!

Please help! Thanks in advance!


Solution

  • replaceRange:withText:
    

    Replace the text in a document that is in the specified range. (required)

    - (void)replaceRange:(UITextRange *)range withText:(NSString *)text
    

    Parameters

    range
    

    A range of text in a document.

    text
    

    A string to replace the text in range.

    Availability Available in iOS 3.2 and later.

    See Also

    – textInRange: 
    

    Declared In UITextInput.h