iPhone Text Field
Question
I have run into an issue that I have yet to be able to solve. Hopefully someone can help. I have an app that I am using to do simple calculations, some of the results are larger than the UItextField. Does anyone know how to limit the output to say 10 characters like say a calculator would using exponents. This is the code I am using currently.
myVar.text = [[NSString alloc]initWithFormat:@"%2.1", myVar]
This just limits the decimal place. The 2 in front of the decimal does nothing.
Solution
You could do it this way. Hope this helps
#define MAX_LENGTH 20
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField.text.length >= MAX_LENGTH && range.length == 0)
{
return NO; // return NO to not change text
}
else
{return YES;}
}
OTHER TIPS
Check here. Sounds like you want 1.2E or _1.2_e.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow