//只能输入两位小数
functextField(_textField:UITextField, shouldChangeCharactersIn range:NSRange, replacementString string:String) ->Bool{
letfutureString:NSMutableString=NSMutableString(string: textField.text!)
futureString.insert(string, at: range.location)
varflag =0;
letlimited =2;//小数点后需要限制的个数
if!futureString.isEqual(to:"") {
foriinstride(from: futureString.length-1,through:0, by:-1) {
letchar =Character(UnicodeScalar(futureString.character(at: i))!)
ifchar=="."{
ifflag>limited {
returnfalse
}
break
}
flag+=1
}
}
returntrue
}