下面的代码限制用户输入textfeld just数字。我想做的是限制用户输入-359到359之间的数字。字母不能只是该范围内的数字。
import UIKit
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet var juju : UITextField!
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let aSet = NSCharacterSet(charactersIn:"0123456789").inverted
let compSepByCharInSet = string.components(separatedBy: aSet)
let numberFiltered = compSepByCharInSet.joined(separator: "")
return string == numberFiltered
}
}