I’d like to place some fixed text inside an UITextField, but before the insert point, sort of like this:
| He went (towaards)
…where “towaards” is the editable part.
The point is to show the editable text in context.
Is that possible, and/or are there better alternatives?
I guess you can do that by implementing
UITextFieldDelegate. There is one method –textField:shouldChangeCharactersInRange:replacementString:.In this method you can check each and every character which is entering by user (even backspace). So first you implement change in another
NSStringobject then validate with your condition.Check whether new string passes through your validation then replace the old string with new string, otherwise leave it as it is.
For example, check new string starts with your string or not. You can use this:
[myString hasPrefix:@"He went"];Here in the same method you can also do one more thing, when user taps on
UITextFieldcheck if@"(towaards)"string is there in textField then remove that text by code.Hope this is what you want.