diff --git a/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift b/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift index 94c37ae..3281aba 100644 --- a/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift +++ b/AnimatedField/Classes/AnimatedField+TextFieldDelegate.swift @@ -19,17 +19,16 @@ extension AnimatedField: UITextFieldDelegate { // Copy new character var newInput = string - - // Replace special characters in newInput - newInput = newInput.replacingOccurrences(of: "`", with: "") - newInput = newInput.replacingOccurrences(of: "^", with: "") - newInput = newInput.replacingOccurrences(of: "¨", with: "") - - // Replace special characters in textField - textField.text = textField.text?.replacingOccurrences(of: "`", with: "") - textField.text = textField.text?.replacingOccurrences(of: "^", with: "") - textField.text = textField.text?.replacingOccurrences(of: "¨", with: "") - + + let invalidCharacters = format.invalidCharacters.map { String($0) } + for invalidCharacter in invalidCharacters { + // Replace special characters in newInput + newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "") + + // Replace special characters in textField + textField.text = textField.text?.replacingOccurrences(of: invalidCharacter, with: "") + } + // Apply uppercased & lowercased if available if uppercased { newInput = newInput.uppercased() } if lowercased { newInput = newInput.lowercased() } diff --git a/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift b/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift index 7214e89..c08a977 100644 --- a/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift +++ b/AnimatedField/Classes/AnimatedField+TextViewDelegate.swift @@ -18,17 +18,16 @@ extension AnimatedField: UITextViewDelegate { // Copy new character var newInput = text - - // Replace special characters in newInput - newInput = newInput.replacingOccurrences(of: "`", with: "") - newInput = newInput.replacingOccurrences(of: "^", with: "") - newInput = newInput.replacingOccurrences(of: "¨", with: "") - - // Replace special characters in textView - textView.text = textView.text?.replacingOccurrences(of: "`", with: "") - textView.text = textView.text?.replacingOccurrences(of: "^", with: "") - textView.text = textView.text?.replacingOccurrences(of: "¨", with: "") - + + let invalidCharacters = format.invalidCharacters.map { String($0) } + for invalidCharacter in invalidCharacters { + // Replace special characters in newInput + newInput = newInput.replacingOccurrences(of: invalidCharacter, with: "") + + // Replace special characters in textView + textView.text = textView.text?.replacingOccurrences(of: invalidCharacter, with: "") + } + // Apply uppercased & lowercased if available if uppercased { newInput = newInput.uppercased() } if lowercased { newInput = newInput.lowercased() } diff --git a/AnimatedField/Classes/AnimatedField.swift b/AnimatedField/Classes/AnimatedField.swift index 319082e..ee3c5f6 100644 --- a/AnimatedField/Classes/AnimatedField.swift +++ b/AnimatedField/Classes/AnimatedField.swift @@ -154,6 +154,10 @@ open class AnimatedField: UIView { didSet { textField.keyboardType = keyboardType } } + public var returnKeyType = UIReturnKeyType.default { + didSet { textField.returnKeyType = returnKeyType } + } + public var keyboardToolbar: UIToolbar? { didSet { textField.inputView = keyboardToolbar } } @@ -317,11 +321,20 @@ open class AnimatedField: UIView { } private func setupDatePicker(mode: UIDatePicker.Mode?, minDate: Date?, maxDate: Date?, chooseText: String?) { - datePicker = UIDatePicker() + datePicker = UIDatePicker(frame: .zero) datePicker?.datePickerMode = mode ?? .date datePicker?.maximumDate = maxDate datePicker?.minimumDate = minDate datePicker?.setValue(format.textColor, forKey: "textColor") + if #available(iOS 13.4, *) { + if #available(iOS 14.0, *) { + datePicker?.preferredDatePickerStyle = .inline + } else { + datePicker?.preferredDatePickerStyle = .wheels + } + } else { + // Fallback on earlier versions + } let toolBar = UIToolbar(target: self, selector: #selector(didChooseDatePicker)) @@ -346,7 +359,13 @@ open class AnimatedField: UIView { textField.inputAccessoryView = accessoryView ?? toolBar textField.inputView = numberPicker } - + + open override var isFirstResponder: Bool { + get { + return textField.isFirstResponder + } + } + open override func becomeFirstResponder() -> Bool { textField.becomeFirstResponder() return super.becomeFirstResponder() diff --git a/AnimatedField/Classes/AnimatedField.xib b/AnimatedField/Classes/AnimatedField.xib index a3734ce..bb30ab1 100644 --- a/AnimatedField/Classes/AnimatedField.xib +++ b/AnimatedField/Classes/AnimatedField.xib @@ -1,9 +1,9 @@ - + - + @@ -32,9 +32,9 @@ - + - + @@ -43,7 +43,7 @@ -