-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable size fields #28
Comments
I would like to use it for an IP Address and i have the same exact question |
@filipealva I don't know if I understand your question, but you can make something like this: `let EXPRESSION: String! = "{ddddd}-{d}" yourTextField.maskTemplate = TEMPLATE |
Hi, |
@andreikeda the problem is that if I use @BruhhGarcia @kvacquier I wind up implementing it by myself using the func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
//Getting the textfield text
var text: NSString = textField.text! as NSString
text = text.replacingCharacters(in: range, with: string) as NSString
//Adding the textfield text on a mutable string
var mutableString: NSMutableString = text.mutableCopy() as! NSMutableString
//Verifying if the user not tapped the delete key
if(!(range.length == 1 && string.lengthOfBytes(using: String.Encoding.utf8) == 0)) {
//Adding the formatter character at the correct position
if (mutableString.length > 1) {
mutableString = (mutableString.replacingOccurrences(of: "-", with: "") as NSString).mutableCopy() as! NSMutableString
mutableString.insert("-", at: mutableString.length - 1)
}
}
let char = string.cString(using: String.Encoding.utf8)!
let isBackSpace = strcmp(char, "\\b")
if (isBackSpace == -92 && mutableString.length > 1) {
mutableString = (mutableString.replacingCharacters(in: NSMakeRange(mutableString.length - 1, 1), with: "") as NSString).mutableCopy() as! NSMutableString
if (mutableString.length > 1) {
mutableString = (mutableString.replacingOccurrences(of: "-", with: "") as NSString).mutableCopy() as! NSMutableString
mutableString.insert("-", at: mutableString.length - 1)
}
}
//Putting the string with the formatter character on the textfield
textField.text = mutableString as String
return false
} Maybe with some adjustments you will be able to adapt it to your needs. |
I have a field which support two number sequences separated by a
-
char.The first sequence can hold 4 or 5 numbers, and the second one can only have one number (0-9).
There is some way to make this mask with
AKMaskField
?Thanks in advance!
The text was updated successfully, but these errors were encountered: