|
|
|
@@ -2,6 +2,7 @@ import UIKit
|
|
|
|
|
|
|
|
|
|
final class SpellingInputView: UIView, UITextFieldDelegate {
|
|
|
|
|
var onChange: (() -> Void)?
|
|
|
|
|
var onSubmit: (() -> Void)?
|
|
|
|
|
|
|
|
|
|
private let hiddenField = UITextField()
|
|
|
|
|
private let stack = UIStackView()
|
|
|
|
@@ -56,6 +57,33 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
|
|
|
|
|
hiddenField.frame = .zero
|
|
|
|
|
addSubview(hiddenField)
|
|
|
|
|
|
|
|
|
|
let accessory = UIView()
|
|
|
|
|
accessory.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 52)
|
|
|
|
|
accessory.backgroundColor = .clear
|
|
|
|
|
|
|
|
|
|
var glassConfig = UIButton.Configuration.glass()
|
|
|
|
|
glassConfig.title = "确认"
|
|
|
|
|
glassConfig.cornerStyle = .fixed
|
|
|
|
|
glassConfig.baseForegroundColor = .label
|
|
|
|
|
glassConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
|
|
|
|
var outgoing = incoming
|
|
|
|
|
outgoing.font = .systemFont(ofSize: 16, weight: .semibold)
|
|
|
|
|
return outgoing
|
|
|
|
|
}
|
|
|
|
|
let glassButton = UIButton(configuration: glassConfig)
|
|
|
|
|
glassButton.addAction(UIAction { [weak self] _ in
|
|
|
|
|
self?.onSubmit?()
|
|
|
|
|
}, for: .touchUpInside)
|
|
|
|
|
glassButton.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
accessory.addSubview(glassButton)
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
glassButton.trailingAnchor.constraint(equalTo: accessory.trailingAnchor, constant: -15),
|
|
|
|
|
glassButton.centerYAnchor.constraint(equalTo: accessory.centerYAnchor),
|
|
|
|
|
glassButton.widthAnchor.constraint(equalToConstant: 60),
|
|
|
|
|
glassButton.heightAnchor.constraint(equalToConstant: 44)
|
|
|
|
|
])
|
|
|
|
|
hiddenField.inputAccessoryView = accessory
|
|
|
|
|
|
|
|
|
|
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reactivate)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|