How to Choose position to print a string in a text?

Asked

Viewed 44 times

0

I’m developing an app where the user can choose in the middle of a text, the position where the output value of a string should be printed. Example: Normally when we print a string in the middle of a text we do so:

 NSLog (@" Um texto com:%@", minhaVariavelString);

Or when we use an Uitextfield:

_meuTextField.text = [NSString stringWithFormat: @"Meu valor:%@.", minhaString];

Maintaining the position of %@ fixed.

However I want to be able to provide the user with the possibility to change the output position of the string on a text composition screen when the app is running.

1 answer

2

Just create a NSMutableString and use the method insertString:AtIndex:.

Example:

NSMutableString *vitima = [NSMutableString stringWithString:@"Minha String Legal"];
NSLog(@"%@", vitima); //Imprime "Minha String Legal"
[vitima insertString:@"Não tão " atIndex:13];
NSLog(@"%@", vitima); //Imprime "Minha String Não tão Legal"
  • Blz! Half way, now I’ll do it in the View, I’ll see if I can do it in a Drag and Drop mode! Vlw!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.