@@ -24,6 +24,7 @@ public class DecimalButtonInputCell: FormInputCell {
2424 }
2525
2626 var numberLocale : Locale ?
27+ private weak var alertController : UIAlertController ?
2728
2829 private lazy var decimalButton : UIButton = {
2930 let button = UIButton ( type: . system)
@@ -109,12 +110,19 @@ public class DecimalButtonInputCell: FormInputCell {
109110
110111 public func showDecimalInput( in viewController: UIViewController ) {
111112 let alertController = UIAlertController ( title: " " , message: nil , preferredStyle: . alert)
113+ self . alertController = alertController
112114
113- alertController. addTextField { textField in
115+ alertController. addTextField { [ weak self] textField in
116+ guard let self = self else { return }
114117 textField. keyboardType = . decimalPad
115118 if let currentValue = self . outputValue {
116119 textField. text = self . numberFormatter. string ( from: currentValue)
117120 }
121+
122+ // Add +/- button to keyboard toolbar
123+ let minusButton = KeyboardToolbarFactory . factoryKeyboardButton ( title: " +/- " )
124+ minusButton. addTarget ( self , action: #selector( self . minusButtonTapped ( _: ) ) , for: . touchUpInside)
125+ textField. inputAccessoryView = KeyboardToolbarFactory . factoryKeyboardToolbar ( leadingButtonList: [ UIBarButtonItem ( customView: minusButton) ] )
118126 }
119127
120128 let cancelAction = UIAlertAction ( title: " Cancel " , style: . cancel)
@@ -142,4 +150,18 @@ public class DecimalButtonInputCell: FormInputCell {
142150
143151 viewController. present ( alertController, animated: true )
144152 }
153+
154+ @objc private func minusButtonTapped( _ button: UIButton ) {
155+ guard let textField = alertController? . textFields? . first,
156+ let text = textField. text else {
157+ return
158+ }
159+
160+ let token = " - "
161+ if text. hasPrefix ( token) {
162+ textField. text = text. replacingOccurrences ( of: token, with: " " )
163+ } else {
164+ textField. text = token + text
165+ }
166+ }
145167}
0 commit comments