0

Say I have a fixed size UITextfield, I want to "display" the associated text starting from the n-th character.

E.g:

Normal UITextField with text set to 'Hello World'

*************
*HELLO WORLD* 
*************

What I want, n-th=4:

*************
*LO WORLD   * 
*************

Some notes: I don't want to modify the UITextfield's text (say: deleting the missing characters), the idea is that the whole text should be there, but the "focus" moved few characters forward.

subzero
  • 3,420
  • 5
  • 31
  • 40
  • did you try textInset ? http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield – Teja Nandamuri Nov 18 '16 at 17:49
  • @TejaNandamuri AFAIK, that will affect where the text starts/ends. -It will move the whole text, and will put me in the same situation. – subzero Nov 18 '16 at 17:55
  • If you aren't dead set on using `UITextField`, you can try using `UITextView` and calculate the position of your character and then scroll to this point. – Rikh Nov 18 '16 at 18:04

1 Answers1

0

You will need to set the UITextPosition when the textfield begins editing like this:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    UITextPosition *beginning = [textField beginningOfDocument];
    [textField setSelectedTextRange:[textField textRangeFromPosition:beginning
toPosition:beginning]];
}

Just set the UITextPosition for whatever index of the textfield's text that you where you would like the cursor to be.

MSU_Bulldog
  • 3,501
  • 5
  • 37
  • 73