I want a \'$\' Sign in the text field which cannot be erased. A user should be able to enter values after it and if he presses backspace it should only erase the value he entere
As noted in the previous answer Add a prefix to UITextField
inside the textFieldDidBeginEditing
as delegate method i found using the following code to be best and right way to format string we are pre/post fixing currency symbols/codes
NSNumberFormatter* formatter = [[NSNumberFormatter alloc]init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setPaddingPosition:NSNumberFormatterPadAfterPrefix];
[formatter setCurrencySymbol:symbol];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:2];
[formatter setUsesGroupingSeparator:YES];
[formatter setCurrencyGroupingSeparator:@","];
[formatter setCurrencyDecimalSeparator:@"."];