限制輸入數(shù)字與指定位數(shù),該點(diǎn)主要留意的是在返回 no 之后, textField 已經(jīng)不能再進(jìn)行操作, 每次輸入會(huì)進(jìn)入該方法. 但是因?yàn)殒I盤(pán)也是一樣需要輸入的, 同樣經(jīng)過(guò)該方法.
`
-
(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
BOOL isOperate = NO;
// 限制輸入位
if (string.hash == 0) {
return YES;
} else {
if (textField.text.length < 5) {
NSCharacterSet *cSet = [[NSCharacterSet characterSetWithCharactersInString: @"0123456789"] invertedSet];
NSString *fil = [[string componentsSeparatedByCharactersInSet: cSet] componentsJoinedByString: @""];
isOperate = [string isEqualToString: fil];
}
}
return isOperate;
}
`