I want numeric keypad which automatically convert the value of textbox开发者_Python百科 into decimal format.for example user types 10 it automatically convert .10
Try the following:
NSString * userInput = textBox.text;
textBox.text = [NSString stringWithFormat:@".%@", userInput];
If you need the value as an integer for other use, try:
int userInput = [textBox.text intValue];
textBox.text = [NSString stringWithFormat:@".%d", userInput];
Also, if you need to know the method to do this in real-time, use:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; {
Make sure to return YES
so that the character gets added! Hope that Helps!
Go for keyboardType property of text field and have ur wanted keyboard type. Set that to UIKeyboardTypeNumberPad
精彩评论