开发者

How to set numeric keypad while clicking on texbox with decimal format?

开发者 https://www.devze.com 2023-04-03 04:08 出处:网络
I want numeric keypad which automatically convert the value of textbox开发者_Python百科into decimal format.for example user types 10 it automatically convert .10Try the following:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消