在 iPhone 应用程序中显示美国格式的电话号码
-
23-09-2019 - |
题
在我的 iPhone 应用程序中,我有一个 textfield
接受电话号码。我需要显示美国电话号码格式中的号码。就像 (000) 000-0000。通常喜欢iPhone联系电话号码条目。我怎样才能做到这一点。任何想法将不胜感激。
没有正确的解决方案
其他提示
您将获得的电话号码格式
HTTP://的-遗失─ beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html
不要忘记使用PhoneNumberFormatter类。该类还availabel在该博客
由于用户在文本字段中手动输入电话号码,就可以“(”第1位之前“)”使用UITextFieldDelegate方法textField:shouldChangeCharactersInRange:replacementString:
为通过将动态地改变所输入的电话号码被输入3位数字之后“ - '后6位数字。
(或)数字输入完成后,可以改变所显示的格式是这样的:
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
//resign the keypad and check if 10 numeric digits entered...
NSRange range;
range.length = 3;
range.location = 3;
textField.text = [NSString stringWithFormat:@"(%@)%@-%@", [textField.text substringToIndex:3], [textField.text substringWithRange:range], [textField.text substringFromIndex:6];
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
//resign the keypad and check if 10 numeric digits entered...
NSRange range;
range.length = 3;
range.location = 3;
textField.text = [NSString stringWithFormat:@"(%@) %@-%@", [textField.text substringToIndex:3], [textField.text substringWithRange:range], [textField.text substringFromIndex:6];
}
不隶属于 StackOverflow