I m using method:
textField:shouldChangeCharactersInRange:replacementString:
There are two UITextFields. First should not have characters limit second should have characters limit.
Please help how to do it.
Thanks in advance.
I m using method:
textField:shouldChangeCharactersInRange:replacementString:
There are two UITextFields. First should not have characters limit second should have characters limit.
Please help how to do it.
Thanks in advance.
Based on the following link Set the maximum character length of a UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField==secondTextField) {
if(range.length + range.location > textField.text.length)
{
return NO;
}
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return newLength <= 10;
} else{
return YES;
}
}
Declare second Textfield as property (var secondTextField). And check it in func
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField == self.secondTextField{
if range.location > yourLimit{
return false
}
}