您的位置:首页 > 产品设计 > UI/UE

限制UITextField手机号只能输入11位

2016-03-30 17:27 302 查看
//输入手机号码

-(UITextField *)phoneNumTF{

if (!_phoneNumTF) {

_phoneNumTF = [[UITextField
alloc] initWithFrame:CGRectMake(0,
65,
kSCreen_width,
60)];

_phoneNumTF.placeholder =
@"请输入账号手机号码";

_phoneNumTF.keyboardType =
UIKeyboardTypeNumberPad;

_phoneNumTF.font = [UIFont
systemFontOfSize:18];

_phoneNumTF.backgroundColor = [UIColor
whiteColor];

_phoneNumTF.delegate =
self;

_phoneNumTF.tag =
100;

UIView *paddingView1 = [[UIView
alloc] initWithFrame:CGRectMake(0,
0, 10,
60)];

_phoneNumTF.leftView = paddingView1;

_phoneNumTF.leftViewMode =
UITextFieldViewModeAlways;

[_phoneNumTF
addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];

}

return
_phoneNumTF;

}

- (void)textFieldDidChange:(UITextField *)textField

{

if (textField ==
self.phoneNumTF) {

if (textField.text.length >
11) {

textField.text = [textField.text
substringToIndex:11];

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: