let futureString: NSMutableString = NSMutableString(string: textField.text!)
futureString.insert(string, at: range.location)
var flag = 0;
let limited = 2;//小數(shù)點(diǎn)后需要限制的個(gè)數(shù)
if !futureString.isEqual(to: "") {
for i in stride(from: (futureString.length - 1), through: 0, by: -1) {
let char = Character(UnicodeScalar(futureString.character(at: i))!)
if char == "." {
if flag > limited {
return false
}
break
}
flag += 1
}
}
return true
這個(gè)很優(yōu)秀