29,028
社区成员
发帖
与我相关
我的任务
分享
@interface PhoneTextField : UITextField<UITextFieldDelegate>
{
NSInteger length;
}
@end
@implementation PhoneTextField
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
length = 11;
self.keyboardType = UIKeyboardTypePhonePad;
self.delegate = self;
}
return self;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location >= length)
return NO; // return NO to not change text
return YES;
}
@end