【发布时间】:2013-12-06 00:15:28
【问题描述】:
我已经尝试了下面的代码,但它只允许输入键盘上的数字。我的应用程序要求键盘使用句点/句号(用于货币交易)。我试过的代码是:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSCharacterSet *nonNumberSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
if ([string rangeOfCharacterFromSet:nonNumberSet].location != NSNotFound)
{
return NO;
}
return YES;
}
感谢您的帮助。
【问题讨论】:
-
将您的文本字段设置为:[textField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
-
@Mutawe 这不会阻止用户更改为
ABC键盘。
标签: ios numbers iphone-keypad